package com.zjsd.sqeybusiness.service.impl;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.domain.server.Sys;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.mapper.SysDeptMapper;
import com.ruoyi.system.mapper.SysUserMapper;
import com.zjsd.sqeybusiness.domain.Achieveold;
import com.zjsd.sqeybusiness.domain.PlatformProductCategory;
import com.zjsd.sqeybusiness.dto.*;
import com.zjsd.sqeybusiness.mapper.AchieveoldMapper;
import org.jpmml.model.NumberUtil;
import org.kie.api.runtime.KieSession;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
import com.zjsd.sqeybusiness.mapper.AchievementsMapper;
import com.zjsd.sqeybusiness.domain.Achievements;
import com.zjsd.sqeybusiness.service.IAchievementsService;

import javax.annotation.Resource;

/**
 * 业务员业绩
Service业务层处理
 *
 * @author Zheng
 * @date 2021-07-14
 */
@Service
public class AchievementsServiceImpl implements IAchievementsService
{
    @Autowired
    private AchievementsMapper achievementsMapper;

    @Autowired
    private TokenService tokenService;

    @Resource
    private KieSession kieSession;

    @Autowired
    private SysDeptMapper sysDeptMapper;

    @Autowired
    private SysUserMapper sysUserMapper;
    @Autowired
    private AchieveoldMapper achieveoldMapper ;

    /**
     * 查询业务员业绩

     *
     * @param achid 业务员业绩
ID
     * @return 业务员业绩

     */
    @Override
    public Achievements selectAchievementsById(Long achid)
    {
        return achievementsMapper.selectAchievementsById(achid);
    }

    /**
     * 查询业务员业绩列表
     *
     * @param achievements 业务员业绩

     * @return 业务员业绩

     */
    @Override
    @DataScope(deptAlias = "d", userAlias = "u")
    public List<Achievements> selectAchievementsList(Achievements achievements)
    {
        Date endDate = achievements.getEndDate();
        if(endDate != null){
            endDate = DateUtils.addDays(endDate,1 );
            endDate = DateUtils.addSeconds(endDate,-1);
            achievements.setEndDate(endDate);
        }

        Date ktEndDate = achievements.getKtEndDate();
        if(ktEndDate != null ){
            ktEndDate = DateUtils.addSeconds(DateUtils.addDays(ktEndDate,1),-1);
            achievements.setKtEndDate(ktEndDate);
        }
        System.out.println("查询业绩明细");
        List<Achievements> list = achievementsMapper.selectAchievementsList(achievements);
        if(list.size() > 0 ){
            for(Achievements temp :list ){
                String paytype = temp.getPaytype();
                if(StringUtils.isNotBlank(paytype)) {
                    temp.setPaytypename(
                    paytype.replace("1","App缴费").replace("2","支付宝").replace("3","银行收款码")
                    .replace("4","银行卡").replace("5","微信转账").replace("6","淘宝").replace("7","随行付"));
                }
                BigDecimal dkssje = temp.getZje();
                if(temp.getDyjgmje() != null){
                    dkssje  = dkssje.subtract(temp.getDyjgmje());
                }
                if(temp.getDybgmje() != null){
                    dkssje  = dkssje.subtract(temp.getDybgmje());
                }
                if(temp.getDyzgmje() != null){
                    dkssje  = dkssje.subtract(temp.getDyzgmje());
                }
                temp.setDkssje(dkssje);
                // 业务类型是打印机、打印包、打印纸时候，端口实收金额为0
                if("5".equals(temp.getYwlx()) || "6".equals(temp.getYwlx()) || "7".equals(temp.getYwlx()) ){
                    temp.setDkssje(BigDecimal.ZERO);
                }

                if("5".equals(temp.getYwlx())){
                    temp.setDyjgmnum(temp.getDknum());
                    temp.setDyjgmje(dkssje);
                    temp.setDknum(BigDecimal.ZERO);
                }

                if("6".equals(temp.getYwlx())){
                    temp.setDybgmnum(temp.getDknum());
                    temp.setDybgmje(dkssje);
                    temp.setDknum(BigDecimal.ZERO);
                }

                if("7".equals(temp.getYwlx())){
                    temp.setDyzgmnum(temp.getDknum());
                    temp.setDyzgmje(dkssje);
                    temp.setDknum(BigDecimal.ZERO);
                }

                if(temp.getTcbdje() != null){
                    continue;
                }
                // 放开限制，查询时候自动更新
                if(StringUtils.isNotBlank(temp.getHdflag())){
                    continue;
                }

                Date nowYear = new Date() ;
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");


                ComputeDeductDTO computeDeductDTO = new ComputeDeductDTO();
                computeDeductDTO.setXtczcflag("1");
                computeDeductDTO.setYwlx(temp.getYwlx());
                computeDeductDTO.setKtlx(temp.getKtlx());
                computeDeductDTO.setDklx(temp.getDklx());
                computeDeductDTO.setDyjlx(temp.getDyjlx());
                computeDeductDTO.setDybtype(temp.getDybtype());
                computeDeductDTO.setPapertype(temp.getPapertype());
                computeDeductDTO.setDknum(temp.getDknum());
                computeDeductDTO.setZje(temp.getZje());
                computeDeductDTO.setJfdkje(temp.getJfdkje());
                if(temp.getDyjzsnum() != null){
                    computeDeductDTO.setDyjzsnum(temp.getDyjzsnum());
                }

                computeDeductDTO.setDyjgmflag(temp.getDyjgmflag());
                computeDeductDTO.setDybgmflag(temp.getDybgmflag());
                computeDeductDTO.setDyzgmflag(temp.getDyzgmflag());
                computeDeductDTO.setDyjgmnum(temp.getDyjgmnum());
                computeDeductDTO.setDyjgmje(temp.getDyjgmje());
                computeDeductDTO.setDybgmnum(temp.getDybgmnum());
                computeDeductDTO.setDybgmje(temp.getDybgmje());
                computeDeductDTO.setDyzgmnum(temp.getDyzgmnum());
                computeDeductDTO.setDyzgmje(temp.getDyzgmje());
                computeDeductDTO.setZnxysnum(temp.getZnxysnum());
                computeDeductDTO.setZnxysdyjnum(temp.getZnxysdyjnum());
                String remark = temp.getRemark();
                if(StringUtils.isNotBlank(remark)){
                    Integer i = remark.indexOf("年");
                    if(i > 0){
                        String num = remark.substring(0,i);
                        computeDeductDTO.setGznx(Integer.valueOf(num));
                    }
                }else {
                    computeDeductDTO.setGznx(0);
                }

                // 云分销新开终生不送打印机
                if("1".equals(computeDeductDTO.getYwlx()) && "1".equals(computeDeductDTO.getKtlx()) && "2".equals(computeDeductDTO.getDklx()) ){
                    BigDecimal dgje = BigDecimal.ZERO ;
                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje = computeDeductDTO.getZje() ;
                        BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                        if(jfdkje != null){
                            zje = zje.add(jfdkje);
                        }
                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyjgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDybgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyzgmje());
                            }
                        }

                        dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);

                        if(dgje != null){
                            if(dgje.compareTo(new BigDecimal(1500)) > 0 && dgje.compareTo(new BigDecimal(2200)) < 0 ){
                                computeDeductDTO.setDgflag("1");
                            }else if(dgje.compareTo(new BigDecimal(1500)) <= 0 ){
                                computeDeductDTO.setDgflag("2");
                            }else{
                                computeDeductDTO.setDgflag("3");
                            }
                        }
                        computeDeductDTO.setDgje(dgje);
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }

                // 云分销续费终生不送打印机
                if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "1".equals(computeDeductDTO.getDklx()) ){
                    BigDecimal dgje = BigDecimal.ZERO ;
                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje = computeDeductDTO.getZje() ;
                        BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                        if(jfdkje != null){
                            zje = zje.add(jfdkje);
                        }
                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyjgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDybgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyzgmje());
                            }
                        }

                        dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                        if(dgje != null){
                            if(dgje.compareTo(new BigDecimal(1500)) > 0 && dgje.compareTo(new BigDecimal(2200)) < 0 ){
                                computeDeductDTO.setDgflag("1");
                            }else if(dgje.compareTo(new BigDecimal(1500)) <= 0 ){
                                computeDeductDTO.setDgflag("2");
                            }else{
                                computeDeductDTO.setDgflag("3");
                            }
                        }
                        computeDeductDTO.setDgje(dgje);
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }

                // 云分销新开终生送58打印机
                if("1".equals(computeDeductDTO.getYwlx()) && "1".equals(computeDeductDTO.getKtlx()) && "1".equals(computeDeductDTO.getDklx())){
                    BigDecimal dgje = BigDecimal.ZERO ;
                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje = computeDeductDTO.getZje() ;
                        BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                        if(jfdkje != null){
                            zje = zje.add(jfdkje);
                        }
                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyjgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDybgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyzgmje());
                            }
                        }

                        if(computeDeductDTO.getDyjzsnum() != null ){
                            // 判断打印机赠送数量和端口数量是否一致，不一致的话，打印机数*2200 + 端口数乘以2400 是否等于总金额
                            if(computeDeductDTO.getDknum().compareTo(computeDeductDTO.getDyjzsnum()) == 0 ){
                                dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                            }else{
                                BigDecimal temp_zje = new BigDecimal(2200)
                                        .multiply(computeDeductDTO.getDknum().subtract(computeDeductDTO.getDyjzsnum()))
                                        .add(new BigDecimal(2400).multiply(computeDeductDTO.getDyjzsnum())) ;

                                if(temp_zje.compareTo(zje) == 0 ){
                                    computeDeductDTO.setDgflag("3");
                                    dgje = new BigDecimal(2400);
                                }else {
                                    dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                                }
                            }
                        }else{
                            dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                        }

                        if(dgje != null && dgje.compareTo(new BigDecimal(2400)) >= 0 ){
                            computeDeductDTO.setDgflag("3");
                        }else{
                            if(dgje != null){
                                if(dgje.compareTo(new BigDecimal(1500)) > 0 ){
                                    computeDeductDTO.setDgflag("1");
                                }else {
                                    computeDeductDTO.setDgflag("2");
                                }
                            }
                        }

                        computeDeductDTO.setDgje(dgje);
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }

                // 云分销续费终生送58打印机
                if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "11".equals(computeDeductDTO.getDklx())){
                    BigDecimal dgje = BigDecimal.ZERO ;
                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje = computeDeductDTO.getZje() ;
                        BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                        if(jfdkje != null){
                            zje = zje.add(jfdkje);
                        }
                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyjgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDybgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyzgmje());
                            }
                        }


                        if(computeDeductDTO.getDyjzsnum() != null ){
                            // 判断打印机赠送数量和端口数量是否一致，不一致的话，打印机数*2200 + 端口数乘以2400 是否等于总金额
                            if(computeDeductDTO.getDknum().compareTo(computeDeductDTO.getDyjzsnum()) == 0 ){
                                dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                            }else{
                                BigDecimal temp_zje = new BigDecimal(2200)
                                        .multiply(computeDeductDTO.getDknum().subtract(computeDeductDTO.getDyjzsnum()))
                                        .add(new BigDecimal(2400).multiply(computeDeductDTO.getDyjzsnum())) ;

                                if(temp_zje.compareTo(zje) == 0 ){
                                    computeDeductDTO.setDgflag("3");
                                    dgje = new BigDecimal(2400);
                                }else {
                                    dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                                }
                            }
                        }else{
                            dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                        }

                        if(dgje != null && dgje.compareTo(new BigDecimal(2400)) >= 0 ){
                            computeDeductDTO.setDgflag("3");
                        }else{
                            if(dgje != null){
                                if(dgje.compareTo(new BigDecimal(1500)) > 0 ){
                                    computeDeductDTO.setDgflag("1");
                                }else {
                                    computeDeductDTO.setDgflag("2");
                                }
                            }
                        }


                        computeDeductDTO.setDgje(dgje);
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }

                // 云分销新开终生送80打印机
                if("1".equals(computeDeductDTO.getYwlx()) && "1".equals(computeDeductDTO.getKtlx()) && "6".equals(computeDeductDTO.getDklx()) ){
                    BigDecimal dgje = BigDecimal.ZERO ;
                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje = computeDeductDTO.getZje() ;
                        BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                        if(jfdkje != null){
                            zje = zje.add(jfdkje);
                        }
                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyjgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDybgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyzgmje());
                            }
                        }

                        if(computeDeductDTO.getDyjzsnum() != null ){
                            // 判断打印机赠送数量和端口数量是否一致，不一致的话，打印机数*2200 + 端口数乘以2400 是否等于总金额
                            if(computeDeductDTO.getDknum().compareTo(computeDeductDTO.getDyjzsnum()) == 0 ){
                                dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                            }else{
                                BigDecimal temp_zje = new BigDecimal(2200)
                                        .multiply(computeDeductDTO.getDknum().subtract(computeDeductDTO.getDyjzsnum()))
                                        .add(new BigDecimal(2400).multiply(computeDeductDTO.getDyjzsnum())) ;

                                if(temp_zje.compareTo(zje) == 0 ){
                                    computeDeductDTO.setDgflag("3");
                                    dgje = new BigDecimal(2400);
                                }else {
                                    dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                                }
                            }
                        }else{
                            dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                        }

                        if(dgje != null && dgje.compareTo(new BigDecimal(2400)) >= 0 ){
                            computeDeductDTO.setDgflag("3");
                        }else{
                            if(dgje != null){
                                if(dgje.compareTo(new BigDecimal(1500)) > 0 ){
                                    computeDeductDTO.setDgflag("1");
                                }else {
                                    computeDeductDTO.setDgflag("2");
                                }
                            }
                        }


                        computeDeductDTO.setDgje(dgje);
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }

                // 云分销新开终生送80打印机
                if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "12".equals(computeDeductDTO.getDklx()) ){
                    BigDecimal dgje = BigDecimal.ZERO ;
                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje = computeDeductDTO.getZje() ;
                        BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                        if(jfdkje != null){
                            zje = zje.add(jfdkje);
                        }
                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyjgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDybgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyzgmje());
                            }
                        }

                        if(computeDeductDTO.getDyjzsnum() != null ){
                            // 判断打印机赠送数量和端口数量是否一致，不一致的话，打印机数*2200 + 端口数乘以2400 是否等于总金额
                            if(computeDeductDTO.getDknum().compareTo(computeDeductDTO.getDyjzsnum()) == 0 ){
                                dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                            }else{
                                BigDecimal temp_zje = new BigDecimal(2200)
                                        .multiply(computeDeductDTO.getDknum().subtract(computeDeductDTO.getDyjzsnum()))
                                        .add(new BigDecimal(2400).multiply(computeDeductDTO.getDyjzsnum())) ;

                                if(temp_zje.compareTo(zje) == 0 ){
                                    computeDeductDTO.setDgflag("3");
                                    dgje = new BigDecimal(2400);
                                }else {
                                    dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                                }
                            }
                        }else{
                            dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                        }

                        if(dgje != null && dgje.compareTo(new BigDecimal(2400)) >= 0 ){
                            computeDeductDTO.setDgflag("3");
                        }else{
                            if(dgje != null){
                                if(dgje.compareTo(new BigDecimal(1500)) > 0 ){
                                    computeDeductDTO.setDgflag("1");
                                }else {
                                    computeDeductDTO.setDgflag("2");
                                }
                            }
                        }

                        computeDeductDTO.setDgje(dgje);
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }

                // 云分销转年限一年转终生

                if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "7".equals(computeDeductDTO.getDklx()) ){
                    BigDecimal dgje = BigDecimal.ZERO ;
                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje = BigDecimal.ZERO ;
                        BigDecimal ynnum = BigDecimal.ZERO ;
                        if(computeDeductDTO.getZnxysnum() != null){
                            zje  = computeDeductDTO.getZje().add(computeDeductDTO.getZnxysnum());
                            ynnum = computeDeductDTO.getZnxysnum().divide(computeDeductDTO.getDknum(),0,BigDecimal.ROUND_HALF_UP);
                        }

                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyjgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDybgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyzgmje());
                            }
                        }


                        BigDecimal pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);

                       /* 终生不再计算打印机
                       if(computeDeductDTO.getZnxysdyjnum() != null){
                            BigDecimal[] results = computeDeductDTO.getZnxysdyjnum().divideAndRemainder(BigDecimal.valueOf(310));
                            BigDecimal[] results1 = computeDeductDTO.getZnxysdyjnum().divideAndRemainder(BigDecimal.valueOf(430));

                            if(results[1].compareTo(BigDecimal.ZERO) == 0 ){
                                computeDeductDTO.setDyjtclx("58");
                                computeDeductDTO.setZnxysjgs(results[0]);
                                if(results[0].compareTo(BigDecimal.ZERO) > 0 ){
                                    dgje = pjje.add(new BigDecimal(122));
                                }else{
                                    dgje = pjje ;
                                }
                                dgje = pjje ;
                            }else{
                                computeDeductDTO.setDyjtclx("80");
                                computeDeductDTO.setZnxysjgs(results1[0]);
                                if(results1[0].compareTo(BigDecimal.ZERO) > 0 ){
                                    dgje = pjje.add(new BigDecimal(142));
                                }else{
                                    dgje = pjje ;
                                }
                            }
                        }*/


                        if(pjje != null){
                            if(pjje.compareTo(new BigDecimal(2200)) >= 0 ){
                                computeDeductDTO.setDgflag("1");
                                if(ynnum.compareTo(new BigDecimal(600)) >= 0 ){
                                    computeDeductDTO.setZcflag("1"); //2022年新政策，一年提成150
                                }else{
                                    computeDeductDTO.setZcflag("2"); // 2021年老政策，一年提成50
                                }
                            }else {
                                computeDeductDTO.setDgflag("2");
                                if(ynnum.compareTo(new BigDecimal(600)) >= 0 ){
                                    computeDeductDTO.setZcflag("1"); //2022年新政策，一年提成150
                                }else{
                                    computeDeductDTO.setZcflag("2"); // 2021年老政策，一年提成50
                                }
                            }
                        }
                        computeDeductDTO.setDgje(pjje);
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }

                // 云分销续费二年转终生
                if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "9".equals(computeDeductDTO.getDklx()) ){
                    BigDecimal dgje = BigDecimal.ZERO ;
                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje = BigDecimal.ZERO;
                        BigDecimal ennum = BigDecimal.ZERO;
                        if(computeDeductDTO.getZnxysnum() != null){
                            zje  = computeDeductDTO.getZje().add(computeDeductDTO.getZnxysnum());
                            ennum = computeDeductDTO.getZnxysnum().divide(computeDeductDTO.getDknum(),0,BigDecimal.ROUND_HALF_UP);
                        }
                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyjgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDybgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyzgmje());
                            }
                        }

                        BigDecimal pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);

                       /* 不再计算打印机
                        if(computeDeductDTO.getZnxysdyjnum() != null){
                            BigDecimal[] results = computeDeductDTO.getZnxysdyjnum().divideAndRemainder(BigDecimal.valueOf(310));
                            BigDecimal[] results1 = computeDeductDTO.getZnxysdyjnum().divideAndRemainder(BigDecimal.valueOf(430));

                            if(results[1].compareTo(BigDecimal.ZERO) == 0 ){
                                computeDeductDTO.setDyjtclx("58");
                                computeDeductDTO.setZnxysjgs(results[0]);
                                if(results[0].compareTo(BigDecimal.ZERO) > 0 ){
                                    dgje = pjje.add(new BigDecimal(122));
                                }else{
                                    dgje = pjje ;
                                }
                                dgje = pjje ;
                            }else{
                                computeDeductDTO.setDyjtclx("80");
                                computeDeductDTO.setZnxysjgs(results1[0]);
                                if(results1[0].compareTo(BigDecimal.ZERO) > 0 ){
                                    dgje = pjje.add(new BigDecimal(142));
                                }else{
                                    dgje = pjje ;
                                }
                            }
                        }*/


                        if(pjje != null){
                            if(pjje.compareTo(new BigDecimal(2200)) >= 0 ){
                                computeDeductDTO.setDgflag("1");
                                // 二年1200
                                if(ennum.compareTo(new BigDecimal(1200)) >= 0 ){
                                    computeDeductDTO.setZcflag("1");
                                }else {
                                    // 二年688
                                    computeDeductDTO.setZcflag("2");
                                }

                            }else {
                                computeDeductDTO.setDgflag("2");

                                if(ennum.compareTo(new BigDecimal(1200)) >= 0 ){
                                    computeDeductDTO.setZcflag("1");
                                }else {
                                    // 二年688
                                    computeDeductDTO.setZcflag("2");
                                }

                            }
                        }
                        computeDeductDTO.setDgje(pjje);
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }

                // 云分销续费三年转终生
                if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "10".equals(computeDeductDTO.getDklx()) ){
                    BigDecimal dgje = BigDecimal.ZERO ;
                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje = BigDecimal.ZERO ;
                        BigDecimal snnum = BigDecimal.ZERO ;
                        if(computeDeductDTO.getZnxysnum() != null){
                            zje  = computeDeductDTO.getZje().add(computeDeductDTO.getZnxysnum());
                            snnum = computeDeductDTO.getZnxysnum().divide(computeDeductDTO.getDknum(),0,BigDecimal.ROUND_HALF_UP);
                        }
                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyjgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDybgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyzgmje());
                            }
                        }

                        BigDecimal pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);

                       /*
                        if(computeDeductDTO.getZnxysdyjnum() != null){
                            BigDecimal[] results = computeDeductDTO.getZnxysdyjnum().divideAndRemainder(BigDecimal.valueOf(310));
                            BigDecimal[] results1 = computeDeductDTO.getZnxysdyjnum().divideAndRemainder(BigDecimal.valueOf(430));

                            if(results[1].compareTo(BigDecimal.ZERO) == 0 ){
                                computeDeductDTO.setDyjtclx("58");
                                computeDeductDTO.setZnxysjgs(results[0]);
                                if(results[0].compareTo(BigDecimal.ZERO) > 0 ){
                                    dgje = pjje.add(new BigDecimal(122));
                                }else{
                                    dgje = pjje ;
                                }
                                dgje = pjje ;
                            }else{
                                computeDeductDTO.setDyjtclx("80");
                                computeDeductDTO.setZnxysjgs(results1[0]);
                                if(results1[0].compareTo(BigDecimal.ZERO) > 0 ){
                                    dgje = pjje.add(new BigDecimal(142));
                                }else{
                                    dgje = pjje ;
                                }
                            }
                        }*/

                        if(pjje != null){
                            if(pjje.compareTo(new BigDecimal(2200)) >= 0 ){
                                computeDeductDTO.setDgflag("1");
                                // 三年1800
                                if(snnum.compareTo(new BigDecimal(1800)) >= 0 ){
                                    computeDeductDTO.setZcflag("1");
                                }else {
                                    // 三年988
                                    computeDeductDTO.setZcflag("2");
                                }
                            }else {
                                computeDeductDTO.setDgflag("2");

                                // 三年1800
                                if(snnum.compareTo(new BigDecimal(1800)) >= 0 ){
                                    computeDeductDTO.setZcflag("1");
                                }else {
                                    // 三年988
                                    computeDeductDTO.setZcflag("2");
                                }
                            }
                        }
                        computeDeductDTO.setDgje(pjje);
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }

                // 云分销续费一年转终生送58打印机
                if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) &&  "13".equals(computeDeductDTO.getDklx()) ){
                    BigDecimal dgje = BigDecimal.ZERO ;
                    BigDecimal ynnum = BigDecimal.ZERO ;
                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje = BigDecimal.ZERO ;
                        if(computeDeductDTO.getZnxysnum() != null){
                            zje  = computeDeductDTO.getZje().add(computeDeductDTO.getZnxysnum());
                            ynnum = computeDeductDTO.getZnxysnum().divide(computeDeductDTO.getDknum(),0,BigDecimal.ROUND_HALF_UP);
                        }

                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyjgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDybgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyzgmje());
                            }
                        }

                        if(computeDeductDTO.getZnxysdyjnum() != null){
                            zje = zje.add(computeDeductDTO.getZnxysdyjnum());
                        }

                       if(computeDeductDTO.getZnxysdyjnum() != null){
                            BigDecimal dyjgs = computeDeductDTO.getZnxysdyjnum().divide(BigDecimal.valueOf(310),0,BigDecimal.ROUND_HALF_UP);
                            // BigDecimal[] results1 = computeDeductDTO.getZnxysdyjnum().divideAndRemainder(BigDecimal.valueOf(430));
                            computeDeductDTO.setDyjtclx("58");
                            if(dyjgs != null){
                                computeDeductDTO.setZnxysjgs(dyjgs);
                            }else {
                                computeDeductDTO.setZnxysjgs(BigDecimal.ZERO);
                            }
                        }


                        BigDecimal pjje = BigDecimal.ZERO ;
                        if(computeDeductDTO.getDyjzsnum() != null ){
                            // 判断打印机赠送数量和端口数量是否一致，不一致的话，打印机数*2200 + 端口数乘以2400 是否等于总金额
                            if(computeDeductDTO.getDknum().compareTo(computeDeductDTO.getDyjzsnum()) == 0 ){
                                pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                            }else{
                                BigDecimal temp_zje = new BigDecimal(2200)
                                        .multiply(computeDeductDTO.getDknum().subtract(computeDeductDTO.getDyjzsnum()))
                                        .add(new BigDecimal(2400).multiply(computeDeductDTO.getDyjzsnum())) ;

                                if(temp_zje.compareTo(zje) == 0 ){
                                    computeDeductDTO.setDgflag("3");
                                    pjje = new BigDecimal(2400);
                                }else {
                                    pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                                }
                            }
                        }else{
                            pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                        }

                        if(pjje != null){
                            if(pjje.compareTo(new BigDecimal(2400)) >= 0 ){
                                computeDeductDTO.setDgflag("1");

                                if(ynnum.compareTo(new BigDecimal(600)) >= 0 ){
                                    computeDeductDTO.setZcflag("1");
                                }else {
                                    // 三年988
                                    computeDeductDTO.setZcflag("2");
                                }

                            }else {
                                computeDeductDTO.setDgflag("2");

                                if(ynnum.compareTo(new BigDecimal(600)) >= 0 ){
                                    computeDeductDTO.setZcflag("1");
                                }else {
                                    // 三年988
                                    computeDeductDTO.setZcflag("2");
                                }
                            }
                        }
                        computeDeductDTO.setDgje(pjje);
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }

                // 云分销续费一年转终生送80打印机
                if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "14".equals(computeDeductDTO.getDklx()) ){
                    BigDecimal dgje = BigDecimal.ZERO ;
                    BigDecimal ynnum = BigDecimal.ZERO ;
                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje = BigDecimal.ZERO ;
                        if(computeDeductDTO.getZnxysnum() != null){
                            zje  = computeDeductDTO.getZje().add(computeDeductDTO.getZnxysnum());
                            ynnum = computeDeductDTO.getZnxysnum().divide(computeDeductDTO.getDknum(),0,BigDecimal.ROUND_HALF_UP);
                        }

                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyjgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDybgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyzgmje());
                            }
                        }

                        if(computeDeductDTO.getZnxysdyjnum() != null){
                            zje = zje.add(computeDeductDTO.getZnxysdyjnum());
                        }

                        if(computeDeductDTO.getZnxysdyjnum() != null){
                            BigDecimal dyjgs = computeDeductDTO.getZnxysdyjnum().divide(BigDecimal.valueOf(430),0,BigDecimal.ROUND_HALF_UP);
                            // BigDecimal[] results1 = computeDeductDTO.getZnxysdyjnum().divideAndRemainder(BigDecimal.valueOf(430));
                            computeDeductDTO.setDyjtclx("80");
                            if(dyjgs != null){
                                computeDeductDTO.setZnxysjgs(dyjgs);
                            }else {
                                computeDeductDTO.setZnxysjgs(BigDecimal.ZERO);
                            }
                        }

                        BigDecimal pjje = BigDecimal.ZERO ;
                        if(computeDeductDTO.getDyjzsnum() != null ){
                            // 判断打印机赠送数量和端口数量是否一致，不一致的话，打印机数*2200 + 端口数乘以2400 是否等于总金额
                            if(computeDeductDTO.getDknum().compareTo(computeDeductDTO.getDyjzsnum()) == 0 ){
                                pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                            }else{
                                BigDecimal temp_zje = new BigDecimal(2200)
                                        .multiply(computeDeductDTO.getDknum().subtract(computeDeductDTO.getDyjzsnum()))
                                        .add(new BigDecimal(2400).multiply(computeDeductDTO.getDyjzsnum())) ;

                                if(temp_zje.compareTo(zje) == 0 ){
                                    computeDeductDTO.setDgflag("3");
                                    pjje = new BigDecimal(2400);
                                }else {
                                    pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                                }
                            }
                        }else{
                            pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                        }

                        if(pjje != null){
                            if(pjje.compareTo(new BigDecimal(2400)) >= 0 ){
                                computeDeductDTO.setDgflag("1");

                                if(ynnum.compareTo(new BigDecimal(600)) >= 0 ){
                                    computeDeductDTO.setZcflag("1");
                                }else {
                                    // 三年988
                                    computeDeductDTO.setZcflag("2");

                                    if(ynnum.compareTo(new BigDecimal(600)) >= 0 ){
                                        computeDeductDTO.setZcflag("1");
                                    }else {
                                        // 三年988
                                        computeDeductDTO.setZcflag("2");
                                    }
                                }
                            }else {
                                computeDeductDTO.setDgflag("2");

                                if(ynnum.compareTo(new BigDecimal(600)) >= 0 ){
                                    computeDeductDTO.setZcflag("1");
                                }else {
                                    // 三年988
                                    computeDeductDTO.setZcflag("2");

                                    if(ynnum.compareTo(new BigDecimal(600)) >= 0 ){
                                        computeDeductDTO.setZcflag("1");
                                    }else {
                                        // 三年988
                                        computeDeductDTO.setZcflag("2");
                                    }
                                }

                            }
                        }
                        computeDeductDTO.setDgje(pjje);
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }

                // 云分销续费二年转终生送58打印机
                if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "15".equals(computeDeductDTO.getDklx())){
                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje = BigDecimal.ZERO ;
                        if(computeDeductDTO.getZnxysnum() != null){
                            zje  = computeDeductDTO.getZje().add(computeDeductDTO.getZnxysnum());
                            BigDecimal ysdgje = computeDeductDTO.getZnxysnum().divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                            String tcfalg = "1";
                            if(ysdgje != null && ysdgje.compareTo(new BigDecimal(1200)) >= 0 ){
                                tcfalg = "1"; // 2022年新政策
                            }else{
                                tcfalg = "2"; // 2021年老政策
                            }
                            computeDeductDTO.setTcflag(tcfalg);
                        }

                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyjgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDybgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyzgmje());
                            }
                        }

                        if(computeDeductDTO.getZnxysdyjnum() != null){
                            zje = zje.add(computeDeductDTO.getZnxysdyjnum());
                        }

                        if(computeDeductDTO.getZnxysdyjnum() != null){
                            BigDecimal dyjgs = computeDeductDTO.getZnxysdyjnum().divide(BigDecimal.valueOf(310),0,BigDecimal.ROUND_HALF_UP);
                            computeDeductDTO.setDyjtclx("58");
                            if(dyjgs != null){
                                computeDeductDTO.setZnxysjgs(dyjgs);
                            }else {
                                computeDeductDTO.setZnxysjgs(BigDecimal.ZERO);
                            }
                        }

                        BigDecimal pjje = BigDecimal.ZERO ;
                        if(computeDeductDTO.getDyjzsnum() != null ){
                            // 判断打印机赠送数量和端口数量是否一致，不一致的话，打印机数*2200 + 端口数乘以2400 是否等于总金额
                            if(computeDeductDTO.getDknum().compareTo(computeDeductDTO.getDyjzsnum()) == 0 ){
                                pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                            }else{
                                BigDecimal temp_zje = new BigDecimal(2200)
                                        .multiply(computeDeductDTO.getDknum().subtract(computeDeductDTO.getDyjzsnum()))
                                        .add(new BigDecimal(2400).multiply(computeDeductDTO.getDyjzsnum())) ;

                                if(temp_zje.compareTo(zje) == 0 ){
                                    computeDeductDTO.setDgflag("3");
                                    pjje = new BigDecimal(2400);
                                }else {
                                    pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                                }
                            }
                        }else{
                            pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                        }

                        if(pjje != null){
                            if(pjje.compareTo(new BigDecimal(2400)) >= 0 ){
                                computeDeductDTO.setDgflag("1");
                            }else {
                                computeDeductDTO.setDgflag("2");
                            }
                        }
                        computeDeductDTO.setDgje(pjje);
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }

                // 云分销续费二年转终生送80打印机
                if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "16".equals(computeDeductDTO.getDklx()) ){
                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje = BigDecimal.ZERO ;
                        if(computeDeductDTO.getZnxysnum() != null){
                            zje  = computeDeductDTO.getZje().add(computeDeductDTO.getZnxysnum());

                            BigDecimal ysdgje = computeDeductDTO.getZnxysnum().divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                            String tcfalg = "1";
                            if(ysdgje != null && ysdgje.compareTo(new BigDecimal(1200)) >= 0 ){
                                tcfalg = "1";
                            }else{
                                tcfalg = "2";
                            }
                            computeDeductDTO.setTcflag(tcfalg);

                        }

                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyjgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDybgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyzgmje());
                            }
                        }

                        if(computeDeductDTO.getZnxysdyjnum() != null){
                            zje = zje.add(computeDeductDTO.getZnxysdyjnum());
                        }

                        if(computeDeductDTO.getZnxysdyjnum() != null){
                            BigDecimal dyjgs = computeDeductDTO.getZnxysdyjnum().divide(BigDecimal.valueOf(430),0,BigDecimal.ROUND_HALF_UP);
                            // BigDecimal[] results1 = computeDeductDTO.getZnxysdyjnum().divideAndRemainder(BigDecimal.valueOf(430));
                            computeDeductDTO.setDyjtclx("80");
                            if(dyjgs != null){
                                computeDeductDTO.setZnxysjgs(dyjgs);
                            }else {
                                computeDeductDTO.setZnxysjgs(BigDecimal.ZERO);
                            }
                        }

                        BigDecimal pjje = BigDecimal.ZERO ;
                        if(computeDeductDTO.getDyjzsnum() != null ){
                            // 判断打印机赠送数量和端口数量是否一致，不一致的话，打印机数*2200 + 端口数乘以2400 是否等于总金额
                            if(computeDeductDTO.getDknum().compareTo(computeDeductDTO.getDyjzsnum()) == 0 ){
                                pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                            }else{
                                BigDecimal temp_zje = new BigDecimal(2200)
                                        .multiply(computeDeductDTO.getDknum().subtract(computeDeductDTO.getDyjzsnum()))
                                        .add(new BigDecimal(2400).multiply(computeDeductDTO.getDyjzsnum())) ;

                                if(temp_zje.compareTo(zje) == 0 ){
                                    computeDeductDTO.setDgflag("3");
                                    pjje = new BigDecimal(2400);
                                }else {
                                    pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                                }
                            }
                        }else{
                            pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                        }

                        if(pjje != null){
                            if(pjje.compareTo(new BigDecimal(2400)) >= 0 ){
                                computeDeductDTO.setDgflag("1");
                            }else {
                                computeDeductDTO.setDgflag("2");
                            }
                        }
                        computeDeductDTO.setDgje(pjje);
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }

                // 云分销续费三年转终生送58打印机
                if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "17".equals(computeDeductDTO.getDklx()) ){

                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje = BigDecimal.ZERO ;
                        if(computeDeductDTO.getZnxysnum() != null){
                            zje  = computeDeductDTO.getZje().add(computeDeductDTO.getZnxysnum());
                            BigDecimal ysdgje = computeDeductDTO.getZnxysnum().divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                            String tcfalg = "1";
                            if(ysdgje != null && ysdgje.compareTo(new BigDecimal(1800)) >= 0 ){
                                tcfalg = "1";
                            }else{
                                tcfalg = "2";
                            }
                            computeDeductDTO.setTcflag(tcfalg);
                        }

                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyjgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDybgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyzgmje());
                            }
                        }

                        if(computeDeductDTO.getZnxysdyjnum() != null){
                            zje = zje.add(computeDeductDTO.getZnxysdyjnum());
                        }

                        if(computeDeductDTO.getZnxysdyjnum() != null){
                            BigDecimal dyjgs = computeDeductDTO.getZnxysdyjnum().divide(BigDecimal.valueOf(310),0,BigDecimal.ROUND_HALF_UP);
                            computeDeductDTO.setDyjtclx("58");
                            if(dyjgs != null){
                                computeDeductDTO.setZnxysjgs(dyjgs);
                            }else {
                                computeDeductDTO.setZnxysjgs(BigDecimal.ZERO);
                            }
                        }

                        BigDecimal pjje = BigDecimal.ZERO ;
                        if(computeDeductDTO.getDyjzsnum() != null ){
                            // 判断打印机赠送数量和端口数量是否一致，不一致的话，打印机数*2200 + 端口数乘以2400 是否等于总金额
                            if(computeDeductDTO.getDknum().compareTo(computeDeductDTO.getDyjzsnum()) == 0 ){
                                pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                            }else{
                                BigDecimal temp_zje = new BigDecimal(2200)
                                        .multiply(computeDeductDTO.getDknum().subtract(computeDeductDTO.getDyjzsnum()))
                                        .add(new BigDecimal(2400).multiply(computeDeductDTO.getDyjzsnum())) ;

                                if(temp_zje.compareTo(zje) == 0 ){
                                    computeDeductDTO.setDgflag("3");
                                    pjje = new BigDecimal(2400);
                                }else {
                                    pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                                }
                            }
                        }else{
                            pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                        }

                        if(pjje != null){
                            if(pjje.compareTo(new BigDecimal(2400)) >= 0 ){
                                computeDeductDTO.setDgflag("1");
                            }else {
                                computeDeductDTO.setDgflag("2");
                            }
                        }
                        computeDeductDTO.setDgje(pjje);
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }

                // 云分销续费二年转终生送80打印机
                if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "18".equals(computeDeductDTO.getDklx()) ){
                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje = BigDecimal.ZERO ;
                        if(computeDeductDTO.getZnxysnum() != null){
                            zje  = computeDeductDTO.getZje().add(computeDeductDTO.getZnxysnum());

                            BigDecimal ysdgje = computeDeductDTO.getZnxysnum().divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                            String tcfalg = "1";
                            if(ysdgje != null && ysdgje.compareTo(new BigDecimal(1800)) >= 0 ){
                                tcfalg = "1";
                            }else{
                                tcfalg = "2";
                            }
                            computeDeductDTO.setTcflag(tcfalg);
                        }

                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyjgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDybgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyzgmje());
                            }
                        }

                        if(computeDeductDTO.getZnxysdyjnum() != null){
                            zje = zje.add(computeDeductDTO.getZnxysdyjnum());
                        }

                        if(computeDeductDTO.getZnxysdyjnum() != null){
                            BigDecimal dyjgs = computeDeductDTO.getZnxysdyjnum().divide(BigDecimal.valueOf(430),0,BigDecimal.ROUND_HALF_UP);
                            computeDeductDTO.setDyjtclx("80");
                            if(dyjgs != null){
                                computeDeductDTO.setZnxysjgs(dyjgs);
                            }else {
                                computeDeductDTO.setZnxysjgs(BigDecimal.ZERO);
                            }
                        }

                        BigDecimal pjje = BigDecimal.ZERO ;
                        if(computeDeductDTO.getDyjzsnum() != null ){
                            // 判断打印机赠送数量和端口数量是否一致，不一致的话，打印机数*2200 + 端口数乘以2400 是否等于总金额
                            if(computeDeductDTO.getDknum().compareTo(computeDeductDTO.getDyjzsnum()) == 0 ){
                                pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                            }else{
                                BigDecimal temp_zje = new BigDecimal(2200)
                                        .multiply(computeDeductDTO.getDknum().subtract(computeDeductDTO.getDyjzsnum()))
                                        .add(new BigDecimal(2400).multiply(computeDeductDTO.getDyjzsnum())) ;

                                if(temp_zje.compareTo(zje) == 0 ){
                                    computeDeductDTO.setDgflag("3");
                                    pjje = new BigDecimal(2400);
                                }else {
                                    pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                                }
                            }
                        }else{
                            pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                        }

                        if(pjje != null){
                            if(pjje.compareTo(new BigDecimal(2400)) >= 0 ){
                                computeDeductDTO.setDgflag("1");
                            }else {
                                computeDeductDTO.setDgflag("2");
                            }
                        }
                        computeDeductDTO.setDgje(pjje);
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }

                //云分销新开一年
                if("1".equals(computeDeductDTO.getYwlx()) && "1".equals(computeDeductDTO.getKtlx()) && "5".equals(computeDeductDTO.getDklx())){
                    BigDecimal dgje = BigDecimal.ZERO ;
                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje  = computeDeductDTO.getZje();
                        BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                        if(jfdkje != null){
                            zje = zje.add(jfdkje);
                        }
                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract(computeDeductDTO.getDyjgmje());
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract((computeDeductDTO.getDybgmje()));
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract((computeDeductDTO.getDyzgmje()));
                            }
                        }

                        dgje = zje.divide((computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);

                        if(dgje != null){
                            if(dgje.compareTo(new BigDecimal(600)) >= 0 ){
                                computeDeductDTO.setDgflag("1");
                            }else {
                                computeDeductDTO.setDgflag("2");
                            }
                        }
                        computeDeductDTO.setDgje(dgje);
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }


                //云分销续费一年
                if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "4".equals(computeDeductDTO.getDklx())){
                    BigDecimal dgje = BigDecimal.ZERO ;
                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje  = computeDeductDTO.getZje();
                        BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                        if(jfdkje != null){
                            zje = zje.add(jfdkje);
                        }
                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract((computeDeductDTO.getDyjgmje()));
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract((computeDeductDTO.getDybgmje()));
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract((computeDeductDTO.getDyzgmje()));
                            }
                        }

                        dgje = zje.divide((computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);

                        if(dgje != null){
                            if(dgje.compareTo(new BigDecimal(600)) >= 0 ){
                                computeDeductDTO.setDgflag("1");
                            }else {
                                computeDeductDTO.setDgflag("2");
                            }
                        }
                        computeDeductDTO.setDgje( dgje );
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }

                // 云分销新开两年
                if("1".equals(computeDeductDTO.getYwlx()) && "1".equals(computeDeductDTO.getKtlx()) && "4".equals(computeDeductDTO.getDklx()) ){
                    BigDecimal dgje = BigDecimal.ZERO ;
                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje  = computeDeductDTO.getZje();
                        BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                        if(jfdkje != null){
                            zje = zje.add(jfdkje);
                        }
                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract((computeDeductDTO.getDyjgmje()));
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract((computeDeductDTO.getDybgmje()));
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract((computeDeductDTO.getDyzgmje()));
                            }
                        }

                        dgje = zje.divide((computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);

                        if(dgje != null){
                            if(dgje.compareTo(new BigDecimal(688)) >= 0 && dgje.compareTo(new BigDecimal(1200)) < 0 ){
                                computeDeductDTO.setDgflag("1");
                            }else if(dgje.compareTo(new BigDecimal(688)) < 0 ){
                                computeDeductDTO.setDgflag("2");
                            }else {
                                computeDeductDTO.setDgflag("3");
                            }
                        }
                        computeDeductDTO.setDgje(dgje);
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }

                // 云分销续费两年
                if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "3".equals(computeDeductDTO.getDklx()) ){
                    BigDecimal dgje = BigDecimal.ZERO ;
                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje  = computeDeductDTO.getZje();
                        BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                        if(jfdkje != null){
                            zje = zje.add(jfdkje);
                        }
                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract( (computeDeductDTO.getDyjgmje()));
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                            }
                        }

                        dgje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);

                        if(dgje != null){
                            if( dgje.compareTo( new BigDecimal(1200)) < 0 ){
                                computeDeductDTO.setDgflag("2");
                            }else {
                                computeDeductDTO.setDgflag("1");
                            }
                        }
                        computeDeductDTO.setDgje(dgje);
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }

                // 云分销新开三年
                if("1".equals(computeDeductDTO.getYwlx()) && "1".equals(computeDeductDTO.getKtlx()) && "3".equals(computeDeductDTO.getDklx()) ){
                    BigDecimal dgje = BigDecimal.ZERO ;
                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje  = computeDeductDTO.getZje();
                        BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                        if(jfdkje != null){
                            zje = zje.add(jfdkje);
                        }
                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract( (computeDeductDTO.getDyjgmje()));
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                            }
                        }

                        dgje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);

                        if(dgje != null){
                            if(dgje.compareTo(new BigDecimal(988)) >= 0 && dgje.compareTo(new BigDecimal(1800)) < 0 ){
                                computeDeductDTO.setDgflag("1");
                            }else if(dgje.compareTo(new BigDecimal(988)) < 0 ){
                                computeDeductDTO.setDgflag("2");
                            }else{
                                computeDeductDTO.setDgflag("3");
                            }
                        }
                        computeDeductDTO.setDgje(dgje);
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }

                // 云分销续费三年
                if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "2".equals(computeDeductDTO.getDklx()) ){
                    BigDecimal dgje = BigDecimal.ZERO ;
                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje  = computeDeductDTO.getZje();
                        BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                        if(jfdkje != null){
                            zje = zje.add(jfdkje);
                        }
                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract( (computeDeductDTO.getDyjgmje()));
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                            }
                        }

                        dgje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);

                        if(dgje != null){
                            if(dgje.compareTo(new BigDecimal(988)) >= 0 && dgje.compareTo(new BigDecimal(1800)) < 0 ){
                                computeDeductDTO.setDgflag("1");
                            }else if(dgje.compareTo(new BigDecimal(988)) < 0 ){
                                computeDeductDTO.setDgflag("2");
                            }else{
                                computeDeductDTO.setDgflag("3");
                            }
                        }
                        computeDeductDTO.setDgje(dgje);
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }



                // 云分销新开,买二送一
                if("1".equals(computeDeductDTO.getYwlx()) && "1".equals(computeDeductDTO.getKtlx()) && "7".equals(computeDeductDTO.getDklx()) ){
                    BigDecimal dgje = BigDecimal.ZERO ;
                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje  = computeDeductDTO.getZje();
                        BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                        if(jfdkje != null){
                            zje = zje.add(jfdkje);
                        }
                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract( (computeDeductDTO.getDyjgmje()));
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                            }
                        }

                        dgje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);

                        if(dgje != null){
                            if(dgje.compareTo(new BigDecimal(1200)) >= 0){
                                computeDeductDTO.setDgflag("1");
                            }else {
                                computeDeductDTO.setDgflag("2");
                            }
                        }
                        computeDeductDTO.setDgje(dgje);
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }


                // 云分销新开,买三送二
                if("1".equals(computeDeductDTO.getYwlx()) && "1".equals(computeDeductDTO.getKtlx()) && "8".equals(computeDeductDTO.getDklx()) ){
                    BigDecimal dgje = BigDecimal.ZERO ;
                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje  = computeDeductDTO.getZje();
                        BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                        if(jfdkje != null){
                            zje = zje.add(jfdkje);
                        }
                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract( (computeDeductDTO.getDyjgmje()));
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                            }
                        }

                        dgje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);

                        if(dgje != null){
                            if(dgje.compareTo(new BigDecimal(1800)) >= 0){
                                computeDeductDTO.setDgflag("1");
                            }else {
                                computeDeductDTO.setDgflag("2");
                            }
                        }
                        computeDeductDTO.setDgje(dgje);
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }


                // 云分销续费，买二送一
                if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "19".equals(computeDeductDTO.getDklx()) ){
                    BigDecimal dgje = BigDecimal.ZERO ;
                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje  = computeDeductDTO.getZje();
                        BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                        if(jfdkje != null){
                            zje = zje.add(jfdkje);
                        }
                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract( (computeDeductDTO.getDyjgmje()));
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                            }
                        }

                        dgje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);

                        if(dgje != null){
                            if(dgje.compareTo(new BigDecimal(1200)) >= 0){
                                computeDeductDTO.setDgflag("1");
                            }else {
                                computeDeductDTO.setDgflag("2");
                            }
                        }
                        computeDeductDTO.setDgje(dgje);
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }


                // 云分销续费，买三送二
                if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "20".equals(computeDeductDTO.getDklx()) ){
                    BigDecimal dgje = BigDecimal.ZERO ;
                    if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                        BigDecimal zje  = computeDeductDTO.getZje();
                        BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                        if(jfdkje != null){
                            zje = zje.add(jfdkje);
                        }
                        if("1".equals(computeDeductDTO.getDyjgmflag())){
                            if(computeDeductDTO.getDyjgmje() != null){
                                zje = zje.subtract( (computeDeductDTO.getDyjgmje()));
                            }

                        }
                        if("1".equals(computeDeductDTO.getDybgmflag())){
                            if(computeDeductDTO.getDybgmje() != null){
                                zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                            }

                        }
                        if("1".equals(computeDeductDTO.getDyzgmflag())){
                            if(computeDeductDTO.getDyzgmje() != null){
                                zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                            }
                        }

                        dgje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);

                        if(dgje != null){
                            if(dgje.compareTo(new BigDecimal(1800)) >= 0){
                                computeDeductDTO.setDgflag("1");
                            }else {
                                computeDeductDTO.setDgflag("2");
                            }
                        }
                        computeDeductDTO.setDgje(dgje);
                    }else{
                        computeDeductDTO.setDgje(BigDecimal.ZERO);
                        computeDeductDTO.setDgflag("2");
                    }
                }


                BigDecimal tczje = BigDecimal.ZERO;
                SysUser sysUser = sysUserMapper.selectUserById(temp.getUserId());
                if(sysUser != null ) {
                    if ("1".equals(sysUser.getXsbz())) {
                        tczje = BigDecimal.ZERO;
                    }else {
                        kieSession.insert(computeDeductDTO);
                        int ruleFiredCount = kieSession.fireAllRules();
                        System.out.println("触发了" + ruleFiredCount + "条规则");
                        System.out.println("提成金额：" + computeDeductDTO.getTcje() + "元");
                        tczje = computeDeductDTO.getTcje();
                        if(tczje == null ){
                            tczje = BigDecimal.ZERO;
                        }
                        if("5".equals(temp.getYwlx())){
                            temp.setDyjtcje(tczje);
                            //temp.setDyjgmje(temp.getZje().longValue());
                        }else if("6".equals(temp.getYwlx())){
                            temp.setDktcje(tczje);
                            //temp.setDybgmje(temp.getZje().longValue());
                        } else if("7".equals(temp.getYwlx())){
                            temp.setDyztcje(tczje);
                            //temp.setDyzgmje(temp.getZje().longValue());
                        }else {
                            temp.setDktcje(tczje);
                        }

                        if(computeDeductDTO.getDyjtcje() != null){
                            tczje = tczje.add(computeDeductDTO.getDyjtcje());
                            temp.setDyjtcje(computeDeductDTO.getDyjtcje());
                        }
                        if(computeDeductDTO.getDyztcje() != null){
                            tczje = tczje.add(computeDeductDTO.getDyztcje());
                            temp.setDyztcje(computeDeductDTO.getDyztcje());
                        }
                    }
                }
                temp.setTcje(tczje);

                achievementsMapper.updateTcje(temp);
            }
        }
        return list;
    }

    /**
     * 新增业务员业绩

     *
     * @param achievements 业务员业绩

     * @return 结果
     */
    @Override
    public int insertAchievements(Achievements achievements)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();
        Long deptid = user.getDeptId();
        Long userid = user.getUserId() ;
        achievements.setUserId( userid);
        achievements.setDeptId(deptid);
        achievements.setLrtime(new Date());
        achievements.setYwyname(loginUser.getUser().getNickName());
        achievements.setRemark(user.getRemark());
        // 计算提成
        Achievements achievements1 = queryTcjeByAchievements(achievements);
        return achievementsMapper.insertAchievements(achievements1);
    }

    /**
     * 修改业务员业绩

     *
     * @param achievements 业务员业绩

     * @return 结果
     */
    @Override
    public int updateAchievements(Achievements achievements)
    {
        Achievements achievements2 = achievementsMapper.selectAchievementsById(achievements.getAchid());
        if(achievements2 != null){
            if(StringUtils.isNotBlank(achievements2.getHdflag())){
                return 2;
                // throw new CustomException("已核对，不允许修改，如需修改，请联系罗英！");
            }

            if( (StringUtils.isNotBlank(achievements2.getYcscflag()) && "1".equals(achievements2.getYcscflag())) || (StringUtils.isNotBlank(achievements2.getZsdkflag()) && "1".equals(achievements2.getZsdkflag()))) {

                if((StringUtils.isNotBlank(achievements2.getCsflag()) && "2".equals(achievements2.getCsflag()))  || (StringUtils.isNotBlank(achievements2.getFsflag()) && "2".equals(achievements2.getFsflag())) ||
                        (StringUtils.isNotBlank(achievements2.getJhflag()) && "2".equals(achievements2.getJhflag()))){
                    Long userid = achievements.getUserId();
                    SysUser sysUser = sysUserMapper.selectUserById(userid);
                    achievements.setRemark(sysUser.getRemark());
                    Achievements achievements1 = queryTcjeByAchievements(achievements);
                    return achievementsMapper.updateAchievements(achievements1);
                }else{
                    if(StringUtils.isNotBlank(achievements2.getJhflag()) && "1".equals(achievements2.getJhflag())){
                        return 3 ;
                    }

                    if(StringUtils.isNotBlank(achievements2.getFsflag()) && "1".equals(achievements2.getFsflag())){
                        return 5 ;
                    }

                    if(StringUtils.isNotBlank(achievements2.getCsflag()) && "1".equals(achievements2.getCsflag())){
                        return 4 ;
                    }
                }
            }else{

                if(StringUtils.isNotBlank(achievements2.getJhflag()) && "1".equals(achievements2.getJhflag())){
                    return 3 ;
                }else{
                    Long userid = achievements.getUserId();
                    SysUser sysUser = sysUserMapper.selectUserById(userid);
                    achievements.setRemark(sysUser.getRemark());
                    Achievements achievements1 = queryTcjeByAchievements(achievements);
                    return achievementsMapper.updateAchievements(achievements1);
                }
            }
        }

        Long userid = achievements.getUserId();
        SysUser sysUser = sysUserMapper.selectUserById(userid);
        achievements.setRemark(sysUser.getRemark());
        Achievements achievements1 = queryTcjeByAchievements(achievements);
        return achievementsMapper.updateAchievements(achievements1);
    }

    /**
     * 审核业务员填报的端口
     * @param achievements
     * @return
     */
    @Override
    public int examAchievements(Achievements achievements) {
        String jhflag = achievements.getJhflag();

        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();

        Long userid = user.getUserId() ;

        if(StringUtils.isNotBlank(achievements.getJhflag())){
            achievements.setJhtime(new Date());
            achievements.setJhuserid(userid);
        }

        if(StringUtils.isNotBlank(achievements.getCsflag())){
            achievements.setFsflag(achievements.getCsflag());
            achievements.setCssj(new Date());
            achievements.setCsuserid(userid);
            achievements.setFssj(new Date());
            achievements.setFsuserid(userid);
            achievements.setFsyj(achievements.getCsyj());
        }

      /*  if(StringUtils.isNotBlank(achievements.getFsflag())){
            achievements.setFssj(new Date());
            achievements.setFsuserid(userid);
        }*/

        String tjbz = achievements.getTjbz() ;

        // 推荐的不再扣除业务员绩效

        /*if((StringUtils.isNotBlank(tjbz) && "1".equals(tjbz)) && (StringUtils.isNotBlank(jhflag) && "1".equals(jhflag))){

            BigDecimal zje = achievements.getZje() ;
            BigDecimal dktcje = achievements.getDktcje() ;
            BigDecimal tcje = achievements.getTcje() ;
            BigDecimal dyjgmje = achievements.getDyjgmje() ;
            BigDecimal dybgmje = achievements.getDybgmje() ;
            BigDecimal dyzgmje = achievements.getDyzgmje() ;

            BigDecimal dkzje = zje.subtract(dyjgmje).subtract( (dybgmje)).subtract( (dyzgmje ));
            String ywlx = achievements.getYwlx() ;
            String ktlx = achievements.getKtlx() ;
            String dklx = achievements.getDklx() ;
            if("1".equals(ywlx) || "2".equals(ywlx) || "3".equals(ywlx) || "4".equals(ywlx) || "8".equals(ywlx)){

                if("1".equals(ktlx)){

                    if("1".equals(dklx) || "2".equals(dklx) || "6".equals(dklx) || "9".equals(dklx) || "10".equals(dklx)){
                        dkzje = new BigDecimal(2600).multiply(achievements.getDknum()).setScale(2,BigDecimal.ROUND_HALF_UP);
                    }
                    BigDecimal jfje = dkzje.multiply(new BigDecimal(0.1)).setScale(2,BigDecimal.ROUND_HALF_UP);
                    tcje = tcje.subtract(jfje);
                    achievements.setTcbdje(jfje.multiply(new BigDecimal(-1)));
                    achievements.setTcje(tcje);
                    achievements.setDktcje(dktcje);
                    achievements.setHdbz("此客户为【" + achievements.getTjrname() + "】推荐客户，提成扣减" + jfje + "元" );
                    achievements.setShyj(achievements.getShyj() + "," + "此客户为【" + achievements.getTjrname() + "】推荐客户，提成扣减" + jfje + "元" );
                }

                if("2".equals(ktlx)){


                    if("1".equals(dklx) || "11".equals(dklx) || "12".equals(dklx) || "21".equals(dklx) || "22".equals(dklx) ){
                        dkzje = new BigDecimal(2600).multiply(achievements.getDknum()).setScale(2,BigDecimal.ROUND_HALF_UP);
                    }

                    BigDecimal jfje = dkzje.multiply(new BigDecimal(0.05)).setScale(2,BigDecimal.ROUND_HALF_UP);
                    tcje = tcje.subtract(jfje);
                    achievements.setTcje(tcje);
                    achievements.setTcbdje(jfje.multiply(new BigDecimal(-1)));
                    achievements.setDktcje(dktcje);
                    achievements.setHdbz("此客户为【" + achievements.getTjrname() + "】推荐客户，提成扣减" + jfje + "元" );
                    achievements.setShyj(achievements.getShyj() + "," + "此客户为【" + achievements.getTjrname() + "】推荐客户，提成扣减" + jfje + "元" );

                }
            }
        }*/

        int i = achievementsMapper.examAchievements(achievements);
        return i;
    }

    /**
     * 批量删除业务员业绩

     *
     * @param achids 需要删除的业务员业绩
ID
     * @return 结果
     */
    @Override
    public int deleteAchievementsByIds(Long[] achids)
    {
        return achievementsMapper.deleteAchievementsByIds(achids);
    }

    /**
     * 删除业务员业绩
信息
     *
     * @param achid 业务员业绩
ID
     * @return 结果
     */
    @Override
    public int deleteAchievementsById(Long achid)
    {

        achievementsMapper.insertIntoAchievementsById(achid);

        return achievementsMapper.deleteAchievementsById(achid);
    }


    @Override
    public List<SysDept> getProvinceList() {

        List<SysDept> sysDeptList = achievementsMapper.selectProvinceList();

        return sysDeptList;
    }

    /**
     * 查询业务员业绩汇总
     * @param computeDeductDTO
     * @return
     */
    @Override
    public MonthDeductDTO queryYwyDeductInfo(ComputeDeductDTO computeDeductDTO) {
        MonthDeductDTO monthDeductDTO = new MonthDeductDTO() ;
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();
        String remark = user.getRemark();
        if(StringUtils.isNotBlank(computeDeductDTO.getRemark())){
            remark   = computeDeductDTO.getRemark();
        }
        if(computeDeductDTO.getUserid() != null ){
            monthDeductDTO.setUserid(computeDeductDTO.getUserid());
        }else{
            monthDeductDTO.setUserid(user.getUserId());
        }

        monthDeductDTO.setYwyname(user.getNickName());

        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        //将小时至0
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        //将分钟至0
        calendar.set(Calendar.MINUTE, 0);
        //将秒至0
        calendar.set(Calendar.SECOND,0);
        //将毫秒至0
        calendar.set(Calendar.MILLISECOND, 0);

        //获得当前月第一天
        Date firstDay = calendar.getTime();
        //将当前月加1；
        calendar.add(Calendar.MONTH, 1);
        //在当前月的下一月基础上减去1毫秒
        calendar.add(Calendar.MILLISECOND, -1);
        //获得当前月最后一天
        Date lastDay = calendar.getTime();
        if(computeDeductDTO.getStartDate() == null ){
            computeDeductDTO.setStartDate(firstDay);
        }
        if(computeDeductDTO.getEndDate() == null ){
            computeDeductDTO.setEndDate(lastDay);
        }
        if(computeDeductDTO.getUserid() == null){
            computeDeductDTO.setUserid(user.getUserId());
        }

        if(StringUtils.isNotBlank(remark)){
            Integer i = remark.indexOf("年");
            if(i > 0){
                String num = remark.substring(0,i);
                computeDeductDTO.setGznx(Integer.valueOf(num));
            }
        }else {
            computeDeductDTO.setGznx(0);
        }

        List<ComputeDeductDTO> list = achievementsMapper.queryYwyDkInfo(computeDeductDTO);

        if(list != null && list.size() > 0 ){
            BigDecimal xkxse = new BigDecimal(0) ; // 新开销售
            BigDecimal xktcje = new BigDecimal(0) ; //新开提成金额
            BigDecimal dktcjeTotal = new BigDecimal(0) ;  // 端口提成金额总和
            BigDecimal zxse = new BigDecimal(0) ; // 总销售额

            BigDecimal yfxxkTotal = BigDecimal.ZERO ;
            BigDecimal yfxxfTotal = BigDecimal.ZERO;
            BigDecimal yfxxktcTotal = BigDecimal.ZERO ;
            BigDecimal yfxxftcTotal = BigDecimal.ZERO ;

            BigDecimal dgjTotal = BigDecimal.ZERO ;
            BigDecimal dgjtcTotal = BigDecimal.ZERO ;

            BigDecimal phtTotal = BigDecimal.ZERO ;
            BigDecimal phttcTotal = BigDecimal.ZERO ;

            BigDecimal zsbiTotal = BigDecimal.ZERO ;
            BigDecimal zsbitcTotal = BigDecimal.ZERO ;

            BigDecimal dyjTotal = BigDecimal.ZERO ;
            BigDecimal dyjtcTotal = BigDecimal.ZERO ;

            BigDecimal dybTotal = BigDecimal.ZERO;
            BigDecimal dybtcTotal = BigDecimal.ZERO;

            BigDecimal dyzTotal = BigDecimal.ZERO;
            BigDecimal dyztcTotal = BigDecimal.ZERO;

            BigDecimal jsxsenum = BigDecimal.ZERO;
            for(ComputeDeductDTO temp :list){
                String xsbz = "0";
                SysUser sysUser = sysUserMapper.selectUserById(temp.getUserid());
                if(sysUser != null ){
                    if("1".equals(sysUser.getXsbz())){
                        xsbz = "1";
                    }
                }
                temp.setGznx(computeDeductDTO.getGznx());
                zxse = zxse.add(temp.getZje());
                BigDecimal dkje = temp.getZje() ;
                if("1".equals(temp.getDyjgmflag())){
                    if(temp.getDyjgmje() != null){
                        dkje = dkje.subtract(temp.getDyjgmje());
                    }
                }
                if("1".equals(temp.getDybgmflag())){
                    if(temp.getDybgmje() != null){
                        dkje = dkje.subtract(temp.getDybgmje());
                    }
                }
                if("1".equals(temp.getDyzgmflag())){
                    if(temp.getDyzgmje() != null){
                        dkje = dkje.subtract(temp.getDyzgmje());
                    }
                }

                // 记录云分销新开销售额，用于计算销售额提成
                if("1".equals(temp.getYwlx()) && "1".equals(temp.getKtlx())){
                    if("0".equals(xsbz)){
                        xkxse = xkxse.add(dkje);
                    }
                }

                BigDecimal tczje = temp.getTcje();
                BigDecimal dktcje = temp.getTcje();
                if(dktcje == null){
                    dktcje = BigDecimal.ZERO;
                }
                if(temp.getDyjtcje() != null ){
                    dktcje = dktcje.subtract(temp.getDyjtcje());
                    if(temp.getDyjgmje() != null && temp.getDyjgmje().compareTo(BigDecimal.ZERO ) >0){
                        dyjTotal = dyjTotal.add(temp.getDyjgmje());
                        dyjtcTotal = dyjtcTotal.add(temp.getDyjtcje());
                    }

                }
                if(temp.getDyztcje() != null ){
                    dktcje = dktcje.subtract(temp.getDyztcje());
                    if(temp.getDyzgmje() != null && temp.getDyzgmje().compareTo(BigDecimal.ZERO ) >0){
                        dyzTotal = dyzTotal.add(temp.getDyzgmje());
                        dyztcTotal = dyztcTotal.add(temp.getDyztcje());
                    }
                }

                if("1".equals(temp.getDybgmflag())){
                    if(temp.getDybgmje() != null){
                        dybTotal = dybTotal.add(temp.getDybgmje());
                    }

                }
                temp.setTcje(tczje);

                // 云分销新开
                if("1".equals(temp.getYwlx()) && "1".equals(temp.getKtlx())){
                    dktcjeTotal = dktcjeTotal.add(dktcje);
                    xktcje = xktcje.add(dktcje);
                    yfxxkTotal = yfxxkTotal.add(dkje);
                    if(temp.getTcje() != null){
                        yfxxktcTotal = yfxxktcTotal.add(dktcje);
                    }
                }
                //云分销续费
                if("1".equals(temp.getYwlx()) && "2".equals(temp.getKtlx())){
                    dktcjeTotal = dktcjeTotal.add(dktcje);
                    yfxxfTotal = yfxxfTotal.add(dkje);
                    if(temp.getTcje() != null){
                        yfxxftcTotal = yfxxftcTotal.add(dktcje);
                    }
                }
                //店管家新开
                if("2".equals(temp.getYwlx())){
                    dktcjeTotal = dktcjeTotal.add(temp.getDktcje() != null ? temp.getDktcje():BigDecimal.ZERO);
                    dgjTotal = dgjTotal.add(temp.getZje() != null ? temp.getZje():BigDecimal.ZERO);
                    if(temp.getTcje() != null ){
                        dgjtcTotal = dgjtcTotal.add(temp.getDktcje() != null ? temp.getDktcje():BigDecimal.ZERO);
                    }
                }
                //拼惠团
                if("3".equals(temp.getYwlx())){
                    dktcjeTotal = dktcjeTotal.add(temp.getZje() != null ? temp.getZje():BigDecimal.ZERO);
                    phtTotal = phtTotal.add(dkje);
                    if(temp.getTcje() != null ){
                        phttcTotal = phttcTotal.add(temp.getDktcje() != null ? temp.getDktcje():BigDecimal.ZERO);
                    }
                }
                //智商BI
                if("4".equals(temp.getYwlx())){
                    dktcjeTotal = dktcjeTotal.add(temp.getDktcje() != null ? temp.getDktcje():BigDecimal.ZERO);
                    zsbiTotal = zsbiTotal.add(temp.getZje() != null ? temp.getZje():BigDecimal.ZERO);
                    if(temp.getTcje() != null ){
                        zsbitcTotal = zsbitcTotal.add(temp.getDktcje() != null ? temp.getDktcje():BigDecimal.ZERO);
                    }
                }

                //打印机
                if("5".equals(temp.getYwlx())){
                    dyjTotal = dyjTotal.add(temp.getZje());
                    if(temp.getTcje() != null){
                        dyjtcTotal = dyjtcTotal.add(temp.getTcje());
                    }
                }
                //打印包
                if("6".equals(temp.getYwlx())){
                    dybTotal = dybTotal.add(temp.getZje());
                    if(temp.getTcje() != null){
                        dybtcTotal = dybtcTotal.add(temp.getTcje());
                    }
                }
                //打印纸
                if("7".equals(temp.getYwlx())){
                    dyzTotal = dyzTotal.add(temp.getZje());
                    if(temp.getTcje() != null ){
                        dyztcTotal = dyztcTotal.add(temp.getTcje());
                    }
                }

                BigDecimal dkssje = temp.getZje();

                if(temp.getDyjgmje() != null){
                    dkssje  = dkssje.subtract(temp.getDyjgmje());
                }
                if(temp.getDybgmje() != null){
                    dkssje  = dkssje.subtract(temp.getDybgmje());
                }
                if(temp.getDyzgmje() != null){
                    dkssje  = dkssje.subtract(temp.getDyzgmje());
                }

                temp.setDkssje(dkssje);

                // 业务类型是打印机、打印包、打印纸时候，端口实收金额为0,计算晋升销售额时候不计算在内
                if("5".equals(temp.getYwlx()) || "6".equals(temp.getYwlx()) || "7".equals(temp.getYwlx()) ){
                    temp.setDkssje(BigDecimal.ZERO);
                }else if("2".equals(temp.getYwlx()) || "3".equals(temp.getYwlx()) || "4".equals(temp.getYwlx() ) || "8".equals(temp.getYwlx() )){
                    // 店管家、拼惠团、智商BI、慧招商平台，直接加实收金额
                    jsxsenum = jsxsenum.add(temp.getDkssje());
                }else{

                    // 云分销新开
                    if("1".equals(temp.getYwlx()) && "1".equals(temp.getKtlx())){

                        //终生端口，计算单个端口金额是否大于2200小于3400，大于2200小于3400按照2200计算，大于3400按3400计算，其他情况按照实际金额计算
                        if( "9".equals(temp.getDklx()) || "10".equals(temp.getDklx())){

                            BigDecimal dgje = BigDecimal.ZERO ;
                            if(temp.getZje() != null && temp.getDknum() != null && temp.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                                BigDecimal zje = temp.getZje() ;
                                if("1".equals(temp.getDyjgmflag())){
                                    if(temp.getDyjgmje() != null){
                                        zje = zje.subtract(temp.getDyjgmje());
                                    }

                                }
                                if("1".equals(temp.getDybgmflag())){
                                    if(temp.getDybgmje() != null){
                                        zje = zje.subtract(temp.getDybgmje());
                                    }

                                }
                                if("1".equals(temp.getDyzgmflag())){
                                    if(temp.getDyzgmje() != null){
                                        zje = zje.subtract(temp.getDyzgmje());
                                    }
                                }

                                dgje = zje.divide(temp.getDknum(),2,BigDecimal.ROUND_HALF_UP);

                                if(dgje != null){

                                    if(dgje.compareTo(new BigDecimal(2600)) >= 0  && dgje.compareTo(new BigDecimal(3400) )  < 0 ){
                                        dgje = new BigDecimal(2600);
                                        BigDecimal dkjeTemp = BigDecimal.ZERO ;
                                        dkjeTemp = dgje.multiply(temp.getDknum());
                                        jsxsenum = jsxsenum.add(dkjeTemp);

                                    }else  if( dgje.compareTo(new BigDecimal(3400)) >= 0 ){

                                        dgje = new BigDecimal(3400);
                                        BigDecimal dkjeTemp = BigDecimal.ZERO ;
                                        dkjeTemp = dgje.multiply(temp.getDknum());
                                        jsxsenum = jsxsenum.add(dkjeTemp);

                                    }else if(dgje.compareTo(new BigDecimal(2200)) >= 0  && dgje.compareTo(new BigDecimal(2600) )  < 0){
                                         dgje = new BigDecimal(2200);
                                        BigDecimal dkjeTemp = BigDecimal.ZERO ;
                                        dkjeTemp = dgje.multiply(temp.getDknum());
                                        jsxsenum = jsxsenum.add(dkjeTemp);
                                    }
                                        else{
                                        jsxsenum = jsxsenum.add(temp.getDkssje());
                                    }
                                }
                            }else{
                                jsxsenum = jsxsenum.add(temp.getDkssje());
                            }
                        }else if("1".equals(temp.getDklx()) || "6".equals(temp.getDklx()) ){
                            BigDecimal dgje = BigDecimal.ZERO ;
                            if(temp.getZje() != null && temp.getDknum() != null && temp.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                                BigDecimal zje = temp.getZje() ;
                                if("1".equals(temp.getDyjgmflag())){
                                    if(temp.getDyjgmje() != null){
                                        zje = zje.subtract(temp.getDyjgmje());
                                    }

                                }
                                if("1".equals(temp.getDybgmflag())){
                                    if(temp.getDybgmje() != null){
                                        zje = zje.subtract(temp.getDybgmje());
                                    }

                                }
                                if("1".equals(temp.getDyzgmflag())){
                                    if(temp.getDyzgmje() != null){
                                        zje = zje.subtract(temp.getDyzgmje());
                                    }
                                }

                                dgje = zje.divide(temp.getDknum(),2,BigDecimal.ROUND_HALF_UP);

                                if(dgje != null){
                                    dgje = dgje.subtract(new BigDecimal(200)) ;
                                    BigDecimal dkjeTemp = BigDecimal.ZERO ;
                                    dkjeTemp = dgje.multiply(temp.getDknum());
                                    BigDecimal dkce = BigDecimal.ZERO;
                                    if(temp.getDknum().compareTo(temp.getDyjzsnum()) > 0 ){
                                        dkce = (temp.getDknum().subtract(temp.getDyjzsnum())).multiply(new BigDecimal(200));
                                    }
                                    jsxsenum = jsxsenum.add(dkjeTemp).add(dkce);
                                }
                            }else{
                                jsxsenum = jsxsenum.add(temp.getDkssje());
                            }
                        }else{
                            jsxsenum = jsxsenum.add(temp.getDkssje());
                        }
                    }

                    if("1".equals(temp.getYwlx()) && "2".equals(temp.getKtlx() )){
                        //云分销续费
                        //终生端口，计算单个端口金额是否大于2200小于3400，大于2200小于3400按照2200计算，大于3400按3400计算，其他情况按照实际金额计算
                        if( "11".equals(temp.getDklx()) || "12".equals(temp.getDklx()) || "13".equals(temp.getDklx()) || "14".equals(temp.getDklx()) || "15".equals(temp.getDklx()) || "16".equals(temp.getDklx()) || "17".equals(temp.getDklx()) || "18".equals(temp.getDklx()) || "21".equals(temp.getDklx()) || "22".equals(temp.getDklx())){

                            BigDecimal dgje = BigDecimal.ZERO ;
                            if(temp.getZje() != null && temp.getDknum() != null && temp.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                                BigDecimal zje = temp.getZje() ;
                                if("1".equals(temp.getDyjgmflag())){
                                    if(temp.getDyjgmje() != null){
                                        zje = zje.subtract(temp.getDyjgmje());
                                    }

                                }
                                if("1".equals(temp.getDybgmflag())){
                                    if(temp.getDybgmje() != null){
                                        zje = zje.subtract(temp.getDybgmje());
                                    }

                                }
                                if("1".equals(temp.getDyzgmflag())){
                                    if(temp.getDyzgmje() != null){
                                        zje = zje.subtract(temp.getDyzgmje());
                                    }
                                }

                                dgje = zje.divide(temp.getDknum(),2,BigDecimal.ROUND_HALF_UP);

                                if(dgje != null){
                                    dgje = dgje.subtract(new BigDecimal(200));
                                    BigDecimal dkjeTemp = BigDecimal.ZERO ;
                                    dkjeTemp = dgje.multiply(temp.getDknum());
                                    BigDecimal dkce = BigDecimal.ZERO;
                                    if(temp.getDknum().compareTo(temp.getDyjzsnum()) > 0 ){
                                        dkce = (temp.getDknum().subtract(temp.getDyjzsnum())).multiply(new BigDecimal(200));
                                    }
                                    jsxsenum = jsxsenum.add(dkjeTemp).add(dkce);
                                }
                            }else{
                                jsxsenum = jsxsenum.add(temp.getDkssje());
                            }
                        }else{
                            jsxsenum = jsxsenum.add(temp.getDkssje());
                        }
                    }
                }


            }

            monthDeductDTO.setJsxsenum(jsxsenum);
            monthDeductDTO.setZxse(zxse);
            monthDeductDTO.setXkxse(xkxse);
            monthDeductDTO.setDktcje(dktcjeTotal);
            monthDeductDTO.setYfxxkTotal(yfxxkTotal);
            monthDeductDTO.setYfxxktcTotal(yfxxktcTotal);
            monthDeductDTO.setYfxxfTotal(yfxxfTotal);
            monthDeductDTO.setYfxxftcTotal(yfxxftcTotal);
            monthDeductDTO.setDgjTotal(dgjTotal);
            monthDeductDTO.setDgjtcTotal(dgjtcTotal);
            monthDeductDTO.setPhtTotal(phtTotal);
            monthDeductDTO.setPhttcTotal(phttcTotal);
            monthDeductDTO.setZsbiTotal(zsbiTotal);
            monthDeductDTO.setZsbitcTotal(zsbitcTotal);
            monthDeductDTO.setDyjTotal(dyjTotal);
            monthDeductDTO.setDyjtcTotal(dyjtcTotal);
            monthDeductDTO.setDybTotal(dybTotal);
            monthDeductDTO.setDybtcTotal(dybtcTotal);
            monthDeductDTO.setDyzTotal(dyzTotal);
            monthDeductDTO.setDyztcTotal(dyztcTotal);
           // monthDeductDTO.setList(list);
            ComputeXseDTO computeXseDTO = new ComputeXseDTO() ;
            computeXseDTO.setXktc(xktcje); // 新开销售额提成金额
            computeXseDTO.setXkxse(xkxse); //新开销售额
            computeXseDTO.setJxse(xkxse.subtract(xktcje));
            monthDeductDTO.setXkjxse(computeXseDTO.getJxse());
            // 计算销售额提成金额
            kieSession.insert(computeXseDTO);
            int ruleFiredCount1 = kieSession.fireAllRules();
            System.out.println("销售额规则：触发了" + ruleFiredCount1 + "条规则");
            System.out.println("销售额提成金额：" + computeXseDTO.getXsetc() + "元");
            if(computeXseDTO.getXsetc() != null ){
                monthDeductDTO.setXsetcje(computeXseDTO.getXsetc().setScale(2,BigDecimal.ROUND_HALF_UP));
            }else{
                monthDeductDTO.setXsetcje(BigDecimal.ZERO);
            }

            if("1".equals(computeXseDTO.getTsflag())){
                monthDeductDTO.setTsmsg("再新开约" + computeXseDTO.getTsmsg() + "个终生端口，可享受第一档销售额提成，提成比例5%");
            }

            if("2".equals(computeXseDTO.getTsflag())){
                monthDeductDTO.setTsmsg("再新开约" + computeXseDTO.getTsmsg() + "个终生端口，可享受第二档销售额提成，提成比例10%");
            }
            if("3".equals(computeXseDTO.getTsflag())){
                monthDeductDTO.setTsmsg("再新开约" + computeXseDTO.getTsmsg() + "个终生端口，可享受第三档销售额提成，提成比例15%");
            }

            if("4".equals(computeXseDTO.getTsflag())){
                monthDeductDTO.setTsmsg("再新开约" + computeXseDTO.getTsmsg() + "个终生端口，可享受第四档销售额提成，提成比例20%");
            }

            if("5".equals(computeXseDTO.getTsflag())){
                monthDeductDTO.setTsmsg("再新开约" +  computeXseDTO.getTsmsg() + "个终生端口，可享受第五档销售额提成，提成比例25%");
            }

            if("6".equals(computeXseDTO.getTsflag())){
                monthDeductDTO.setTsmsg("您已达到享受销售额提成的第五档，提成比例25%");
            }

            //销售额提成已取消
            /*if(computeXseDTO.getXsetc() != null ){
                monthDeductDTO.setZtcje(
                        monthDeductDTO.getDktcje()
                                .add(computeXseDTO.getXsetc())
                                .add(monthDeductDTO.getDyjtcTotal())
                                .add(monthDeductDTO.getDybtcTotal())
                                .add(monthDeductDTO.getDyztcTotal())
                                .setScale(2,BigDecimal.ROUND_HALF_UP));
            }else {
                monthDeductDTO.setZtcje
                        (monthDeductDTO.getDktcje()
                                .add(monthDeductDTO.getDyjtcTotal())
                                .add(monthDeductDTO.getDybtcTotal())
                                .add(monthDeductDTO.getDyztcTotal())
                            .setScale(2,BigDecimal.ROUND_HALF_UP));
            }*/

            monthDeductDTO.setZtcje
                    (monthDeductDTO.getDktcje()
                            .add(monthDeductDTO.getDyjtcTotal())
                            .add(monthDeductDTO.getDybtcTotal())
                            .add(monthDeductDTO.getDyztcTotal())
                            .setScale(2,BigDecimal.ROUND_HALF_UP));
        }

        ParamDTO paramDTO = new ParamDTO();
        paramDTO.setStartDate(firstDay);
        paramDTO.setEndDate(lastDay);
        paramDTO.setUserid( computeDeductDTO.getUserid());
        MonthDeductDTO monthDeductDTO1 =  achievementsMapper.queryYwyFy(paramDTO);
        if(monthDeductDTO1 != null){
            monthDeductDTO.setFyzje(monthDeductDTO1.getFyzje());
        }
        return monthDeductDTO;
    }

    /**
     * 后台管理系统查询业务员业绩情况
     * 计算绩效总金额
     * @param queryDTO
     * @return
     */
    @Override
    public List<EmployeeDeductDTO> queryEmployeeDeduct(QueryDTO queryDTO) {
        System.out.println("开始时间：" + queryDTO.getStartDate());
        System.out.println("结束时间：" + queryDTO.getEndDate());
        List<EmployeeDeductDTO> employeeDeductDTOList = achievementsMapper.queryEmployeeList(queryDTO);
        if(employeeDeductDTOList != null && employeeDeductDTOList.size() > 0 ){
            for(EmployeeDeductDTO temp : employeeDeductDTOList){
                queryDTO.setUserid(temp.getUserid());
                EmployeeDeductDTO employeeDeductDTO = achievementsMapper.queryPsnlDeductData(queryDTO);
                if(employeeDeductDTO != null ){
                    BeanUtils.copyProperties(employeeDeductDTO,temp,new String[]{"userid","ywyname","deptid","deptname","remark","jobnum","postname"});

                    temp.setSsjexj(
                            temp.getXkzje()
                                    .add(temp.getXkznxzje())
                            .add(temp.getXfzje())
                            .add(temp.getZnxzje())
                            .add(temp.getDgjzje())
                            .add(temp.getPhtzje())
                            .add(temp.getZsbizje())
                            .add(temp.getDyjzje())
                            .add(temp.getDybzje())
                            .add(temp.getDyzzje())
                    );

                    temp.setJfdkxj(
                            temp.getXkjfze().add(temp.getXfjfze())
                    );
                }else{
                    temp.setXktwoyearnum(BigDecimal.ZERO);
                    temp.setXkzsswbnum(BigDecimal.ZERO);
                    temp.setXkzsbsnum(BigDecimal.ZERO);
                    temp.setXkthreeyearnum(BigDecimal.ZERO);
                    temp.setXkoneyearnum(BigDecimal.ZERO);
                    temp.setXkzssblnum(BigDecimal.ZERO);
                    temp.setXkzsbsnum(BigDecimal.ZERO);
                    temp.setXfzsbsnum(BigDecimal.ZERO);
                    temp.setXfthreeyearnum(BigDecimal.ZERO);
                    temp.setXftwoyearnum(BigDecimal.ZERO);
                    temp.setXfoneyearnum(BigDecimal.ZERO);
                    temp.setOnetothreenum(BigDecimal.ZERO);
                    temp.setOnetothreenum(BigDecimal.ZERO);
                    temp.setOnetozsnum(BigDecimal.ZERO);
                    temp.setTwotothreenum(BigDecimal.ZERO);
                    temp.setTwotozsnum(BigDecimal.ZERO);
                    temp.setThreetozsnum(BigDecimal.ZERO);
                    temp.setXfzsswbnum(BigDecimal.ZERO);
                    temp.setXfzssblnum(BigDecimal.ZERO);
                    temp.setDgjbbnfnum(BigDecimal.ZERO);
                    temp.setDgjlqnfnum(BigDecimal.ZERO);
                    temp.setDgjbxnfnum(BigDecimal.ZERO);
                    temp.setDgjbbzsnum(BigDecimal.ZERO);
                    temp.setDgjlqzsnum(BigDecimal.ZERO);
                    temp.setDgjbxzsnum(BigDecimal.ZERO);
                    temp.setDgjdzbnum(BigDecimal.ZERO);
                    temp.setPhtnum(BigDecimal.ZERO);
                    temp.setZsbinum(BigDecimal.ZERO);
                    temp.setDyjwbnum(BigDecimal.ZERO);
                    temp.setDyjblnum(BigDecimal.ZERO);
                    temp.setDybwbnum(BigDecimal.ZERO);
                    temp.setDybblnum(BigDecimal.ZERO);
                    temp.setDyzwbnum(BigDecimal.ZERO);
                    temp.setDyzblnum(BigDecimal.ZERO);
                    temp.setZswbdyjnum(BigDecimal.ZERO);
                    temp.setZsbldyjnum(BigDecimal.ZERO);
                    temp.setZswbdybnum(BigDecimal.ZERO);
                    temp.setZsbldybnum(BigDecimal.ZERO);
                    temp.setXkzje(BigDecimal.ZERO);
                    temp.setXkznxzje(BigDecimal.ZERO);
                    temp.setXkjfze(BigDecimal.ZERO);
                    temp.setXfzje(BigDecimal.ZERO);
                    temp.setZnxzje(BigDecimal.ZERO);
                    temp.setXfjfze(BigDecimal.ZERO);
                    temp.setDgjzje(BigDecimal.ZERO);
                    temp.setPhtzje(BigDecimal.ZERO);
                    temp.setZsbizje(BigDecimal.ZERO);
                    temp.setDyjzje(BigDecimal.ZERO);
                    temp.setDybzje(BigDecimal.ZERO);
                    temp.setDyzzje(BigDecimal.ZERO);
                    temp.setZnxdkysNum(BigDecimal.ZERO);
                    temp.setZnxdyjysNum(BigDecimal.ZERO);
                    temp.setWxcostnum(BigDecimal.ZERO);
                    temp.setSsjexj(BigDecimal.ZERO);
                    temp.setJfdkxj(BigDecimal.ZERO);
                    temp.setOnetotwonum(BigDecimal.ZERO);

                    temp.setXkyzsnum(BigDecimal.ZERO);
                    temp.setXkyzwnum(BigDecimal.ZERO);
                    temp.setXkyzzsswbnum(BigDecimal.ZERO);
                    temp.setXkyzzssblnum(BigDecimal.ZERO);
                    temp.setXkyzzsbsnum(BigDecimal.ZERO);
                    temp.setXkszzsbsnum(BigDecimal.ZERO);
                    temp.setXkszzssblnum(BigDecimal.ZERO);
                    temp.setXkszzsswbnum(BigDecimal.ZERO);
                    temp.setXkwzzsbsnum(BigDecimal.ZERO);
                    temp.setXkwzzssblnum(BigDecimal.ZERO);
                    temp.setXkwzzsswbnum(BigDecimal.ZERO);
                }
                // 计算提成
                ComputeDeductDTO computeDeductDTO = new ComputeDeductDTO() ;
                computeDeductDTO.setUserid( temp.getUserid());
                computeDeductDTO.setStartDate(queryDTO.getStartDate());
                computeDeductDTO.setEndDate(queryDTO.getEndDate());
                computeDeductDTO.setRemark(temp.getRemark());
                MonthDeductDTO monthDeductDTO = queryYwyDeductInfo(computeDeductDTO);
                if(monthDeductDTO != null ){
                    if(monthDeductDTO.getYfxxktcTotal() != null ){
                        temp.setXkdktc(monthDeductDTO.getYfxxktcTotal());
                    }else {
                        temp.setXkdktc(BigDecimal.ZERO);
                    }

                    if(monthDeductDTO.getYfxxftcTotal() != null ){
                        temp.setXfdktc(monthDeductDTO.getYfxxftcTotal());
                    }else {
                        temp.setXfdktc(BigDecimal.ZERO);
                    }

                    if(monthDeductDTO.getXsetcje() != null ){
                        temp.setXsetc(monthDeductDTO.getXsetcje());
                    }else {
                        temp.setXsetc(BigDecimal.ZERO);
                    }

                    if(monthDeductDTO.getDgjtcTotal() != null ){
                        temp.setDgjtc(monthDeductDTO.getDgjtcTotal());
                    }else {
                        temp.setDgjtc(BigDecimal.ZERO);
                    }

                    if(monthDeductDTO.getPhttcTotal() != null ){
                        temp.setPhttc(monthDeductDTO.getPhttcTotal());
                    }else {
                        temp.setPhttc(BigDecimal.ZERO);
                    }

                    if(monthDeductDTO.getZsbitcTotal() != null ){
                        temp.setZsbitc(monthDeductDTO.getZsbitcTotal());
                    }else {
                        temp.setZsbitc(BigDecimal.ZERO);
                    }

                    if(monthDeductDTO.getDyjtcTotal() != null ){
                        temp.setDyjtc(monthDeductDTO.getDyjtcTotal());
                    }else {
                        temp.setDyjtc(BigDecimal.ZERO);
                    }
                    if(monthDeductDTO.getXkjxse() != null ){
                        temp.setXkjxse(monthDeductDTO.getXkjxse());
                    }else {
                        temp.setXkjxse(BigDecimal.ZERO);
                    }

                    if(monthDeductDTO.getDyztcTotal() != null ){
                        temp.setDyztc(monthDeductDTO.getDyztcTotal());
                    }else {
                        temp.setDyztc(BigDecimal.ZERO);
                    }

                }else{
                    temp.setXkdktc(BigDecimal.ZERO);
                    temp.setXfdktc(BigDecimal.ZERO);
                    temp.setXsetc(BigDecimal.ZERO);
                    temp.setDgjtc(BigDecimal.ZERO);
                    temp.setPhttc(BigDecimal.ZERO);
                    temp.setZsbitc(BigDecimal.ZERO);
                    temp.setDyjtc(BigDecimal.ZERO);
                    temp.setDyztc(BigDecimal.ZERO);
                    temp.setXkjxse(BigDecimal.ZERO);
                }

            }
        }
        return employeeDeductDTOList;
    }

    // 根据保存的提成金额查询汇总情况
    @Override
    public List<EmployeeDeductDTO> queryEmployeeDeductNew(QueryDTO queryDTO) {

        System.out.println("开始时间：" + queryDTO.getStartDate());
        System.out.println("结束时间：" + queryDTO.getEndDate());

        Date endDate = queryDTO.getEndDate();
        if(endDate != null){
            endDate = DateUtils.addDays(endDate,1 );
            endDate = DateUtils.addSeconds(endDate,-1);
            queryDTO.setEndDate(endDate);
        }

        Date ktEndDate = queryDTO.getKtEndDate();
        if(ktEndDate != null){
            ktEndDate = DateUtils.addSeconds(DateUtils.addDays(ktEndDate,1),-1);
            queryDTO.setKtEndDate(ktEndDate);
        }

        List<EmployeeDeductDTO> employeeDeductDTOList = achievementsMapper.queryEmployeeList(queryDTO);
        if(employeeDeductDTOList != null && employeeDeductDTOList.size() > 0 ){
            for(EmployeeDeductDTO temp : employeeDeductDTOList){
                queryDTO.setUserid(temp.getUserid());
                System.out.println("查询业绩汇总");
                EmployeeDeductDTO employeeDeductDTO = achievementsMapper.queryPsnlDeductData(queryDTO);
                if(employeeDeductDTO != null ){
                    BeanUtils.copyProperties(employeeDeductDTO,temp,new String[]{"userid","ywyname","deptid","deptname","remark","jobnum","postname"});

                    temp.setSsjexj( //实收金额小计
                            temp.getXkzje()
                                    .add(temp.getXkznxzje())
                                    .add(temp.getXfzje())
                                    .add(temp.getZnxzje())
                                    .add(temp.getDgjzje())
                                    .add(temp.getPhtzje())
                                    .add(temp.getZsbizje())
                                    .add(temp.getDyjzje())
                                    .add(temp.getDybzje())
                                    .add(temp.getDyzzje())
                    );

                    temp.setJfdkxj(temp.getXkjfze().add(temp.getXfjfze()));

                    Achievements queryAchievements = new Achievements() ;
                    queryAchievements.setUserId(queryDTO.getUserid());
                    queryAchievements.setDeptId(queryDTO.getDeptId());
                    queryAchievements.setStartDate(queryDTO.getStartDate());
                    queryAchievements.setEndDate(queryDTO.getEndDate());
                    queryAchievements.setKtStartDate(queryDTO.getKtStartDate());
                    queryAchievements.setKtEndDate(queryDTO.getKtEndDate());
                    queryAchievements.setYwyname(queryDTO.getYwyname());
                    queryAchievements.setYwlx(queryDTO.getYwlx());
                    List<Achievements> list = achievementsMapper.selectAchievementsList(queryAchievements);

                    BigDecimal jsxsenum = BigDecimal.ZERO;

                    if(list.size() > 0 ){
                        for(Achievements tempAch :list ){

                            String paytype = tempAch.getPaytype();

                            if(StringUtils.isNotBlank(paytype)) {
                                tempAch.setPaytypename(
                                        paytype.replace("1","App缴费").replace("2","支付宝").replace("3","银行收款码")
                                                .replace("4","银行卡").replace("5","微信转账").replace("6","淘宝").replace("7","随行付"));
                            }

                            BigDecimal dkssje = tempAch.getZje();

                            if(tempAch.getDyjgmje() != null){
                                dkssje  = dkssje.subtract(tempAch.getDyjgmje());
                            }
                            if(tempAch.getDybgmje() != null){
                                dkssje  = dkssje.subtract(tempAch.getDybgmje());
                            }
                            if(tempAch.getDyzgmje() != null){
                                dkssje  = dkssje.subtract(tempAch.getDyzgmje());
                            }

                            tempAch.setDkssje(dkssje);

                            // 业务类型是打印机、打印包、打印纸时候，端口实收金额为0,计算晋升销售额时候不计算在内
                            if("5".equals(tempAch.getYwlx()) || "6".equals(tempAch.getYwlx()) || "7".equals(tempAch.getYwlx()) ){
                                tempAch.setDkssje(BigDecimal.ZERO);
                            }else if("2".equals(tempAch.getYwlx()) || "3".equals(tempAch.getYwlx()) || "4".equals(tempAch.getYwlx() ) || "8".equals(tempAch.getYwlx() )){
                                // 店管家、拼惠团、智商BI、慧招商平台，直接加实收金
                                jsxsenum = jsxsenum.add(tempAch.getDkssje());
                            }else{

                                // 云分销新开
                                if("1".equals(tempAch.getYwlx()) && "1".equals(tempAch.getKtlx())){

                                    //终生端口，计算单个端口金额是否大于2200小于3400，大于2200小于3400按照2200计算，大于3400按3400计算，其他情况按照实际金额计算
                                    if("1".equals(tempAch.getDklx()) || "6".equals(tempAch.getDklx()) || "9".equals(tempAch.getDklx()) || "10".equals(tempAch.getDklx()) || "13".equals(tempAch.getDklx() )
                                        || "14".equals(tempAch.getDklx()) || "15".equals(tempAch.getDklx()) || "16".equals(tempAch.getDklx()) || "17".equals(tempAch.getDklx())
                                        || "18".equals(tempAch.getDklx())  ){

                                        BigDecimal dgje = BigDecimal.ZERO ;
                                        if(tempAch.getZje() != null && tempAch.getDknum() != null && tempAch.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                                            BigDecimal zje = tempAch.getZje() ;
                                            if("1".equals(tempAch.getDyjgmflag())){
                                                if(tempAch.getDyjgmje() != null){
                                                    zje = zje.subtract(tempAch.getDyjgmje());
                                                }

                                            }
                                            if("1".equals(tempAch.getDybgmflag())){
                                                if(tempAch.getDybgmje() != null){
                                                    zje = zje.subtract(tempAch.getDybgmje());
                                                }

                                            }
                                            if("1".equals(tempAch.getDyzgmflag())){
                                                if(tempAch.getDyzgmje() != null){
                                                    zje = zje.subtract(tempAch.getDyzgmje());
                                                }
                                            }

                                            dgje = zje.divide(tempAch.getDknum(),2,BigDecimal.ROUND_HALF_UP);

                                            if(dgje != null){
                                                dgje = dgje.subtract(new BigDecimal(200));
                                                BigDecimal dkje = BigDecimal.ZERO ;
                                                dkje = dgje.multiply(tempAch.getDknum());
                                                System.out.println("晋升销售额1：" + dkje );
                                                BigDecimal dkce = BigDecimal.ZERO;
                                                if(tempAch.getDknum().compareTo(tempAch.getDyjzsnum()) > 0 ){
                                                    dkce = (tempAch.getDknum().subtract(tempAch.getDyjzsnum())).multiply(new BigDecimal(200));
                                                }
                                                jsxsenum = jsxsenum.add(dkje).add(dkce);
                                            }
                                        }else{
                                            System.out.println("晋升销售额11：" + tempAch.getDkssje() );
                                            jsxsenum = jsxsenum.add(tempAch.getDkssje());
                                        }
                                    }else{
                                        System.out.println("晋升销售额12：" + tempAch.getDkssje() );
                                        jsxsenum = jsxsenum.add(tempAch.getDkssje());
                                    }
                                }

                                if("1".equals(tempAch.getYwlx()) && "2".equals(tempAch.getKtlx() )){
                                    //云分销续费

                                    //终生端口，计算单个端口金额是否大于2200小于3400，大于2200小于3400按照2200计算，大于3400按3400计算，其他情况按照实际金额计算
                                    if("11".equals(tempAch.getDklx()) || "12".equals(tempAch.getDklx()) || "21".equals(tempAch.getDklx()) || "22".equals(tempAch.getDklx()) || "13".equals(tempAch.getDklx() )
                                            || "14".equals(tempAch.getDklx()) || "15".equals(tempAch.getDklx()) || "16".equals(tempAch.getDklx()) || "17".equals(tempAch.getDklx())
                                            || "18".equals(tempAch.getDklx())){

                                            BigDecimal dgje = BigDecimal.ZERO ;
                                            if(tempAch.getZje() != null && tempAch.getDknum() != null && tempAch.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                                                BigDecimal zje = tempAch.getZje() ;
                                                if("1".equals(tempAch.getDyjgmflag())){
                                                    if(tempAch.getDyjgmje() != null){
                                                        zje = zje.subtract(tempAch.getDyjgmje());
                                                    }

                                                }
                                                if("1".equals(tempAch.getDybgmflag())){
                                                    if(tempAch.getDybgmje() != null){
                                                        zje = zje.subtract(tempAch.getDybgmje());
                                                    }

                                                }
                                                if("1".equals(tempAch.getDyzgmflag())){
                                                    if(tempAch.getDyzgmje() != null){
                                                        zje = zje.subtract(tempAch.getDyzgmje());
                                                    }
                                                }

                                                dgje = zje.divide(tempAch.getDknum(),2,BigDecimal.ROUND_HALF_UP);

                                                if(dgje != null){
                                                    dgje = dgje.subtract(new BigDecimal(200));
                                                    BigDecimal dkje = BigDecimal.ZERO ;
                                                    dkje = dgje.multiply(tempAch.getDknum());
                                                    System.out.println("晋升销售额2：" + dkje );
                                                    BigDecimal dkce = BigDecimal.ZERO;
                                                    if(tempAch.getDknum() != null && tempAch.getDyjzsnum() != null){
                                                        if(tempAch.getDknum().compareTo(tempAch.getDyjzsnum()) > 0 ){
                                                            dkce = (tempAch.getDknum().subtract(tempAch.getDyjzsnum())).multiply(new BigDecimal(200));
                                                        }
                                                    }
                                                    jsxsenum = jsxsenum.add(dkje).add(dkce);
                                                }
                                            }else{
                                                System.out.println("晋升销售额2：" +tempAch.getDkssje());
                                                jsxsenum = jsxsenum.add(tempAch.getDkssje());
                                            }
                                    }else{
                                        System.out.println("晋升销售额2：" +tempAch.getDkssje());

                                        jsxsenum = jsxsenum.add(tempAch.getDkssje());
                                    }
                                }
                            }
                        }
                    }
                    System.out.println("晋升销售额：" +jsxsenum);

                    temp.setJsxsenum(jsxsenum);
                    /*

                    temp.setJsxsenum( //晋升销售额，所有软件收入
                            temp.getXkzje()  // 新开总金额
                                    .add(temp.getXfzje())  // 续费总金额
                                    .add(temp.getZnxzje())  // 20220221 ，罗英提算进去，要看刘英贺12月份业绩累计够10万否 ,转年限总金额
                                    .add(temp.getDgjzje()) // 店管家总金额
                                    .add(temp.getPhtzje()) // 拼惠团总金额
                                    .add(temp.getZsbizje()) //智商BI总金额
                                    //.add(temp.getDyjzje())
                                    //.add(temp.getDybzje())
                                    //.add(temp.getDyzzje())
                    );
                     */
                }else{
                    temp.setXktwoyearnum(BigDecimal.ZERO);
                    temp.setXkzsswbnum(BigDecimal.ZERO);
                    temp.setXkzsbsnum(BigDecimal.ZERO);
                    temp.setXkthreeyearnum(BigDecimal.ZERO);
                    temp.setXkoneyearnum(BigDecimal.ZERO);
                    temp.setXkzssblnum(BigDecimal.ZERO);
                    temp.setXkzsbsnum(BigDecimal.ZERO);
                    temp.setXfzsbsnum(BigDecimal.ZERO);
                    temp.setXfthreeyearnum(BigDecimal.ZERO);
                    temp.setXftwoyearnum(BigDecimal.ZERO);
                    temp.setXfoneyearnum(BigDecimal.ZERO);
                    temp.setOnetothreenum(BigDecimal.ZERO);
                    temp.setOnetothreenum(BigDecimal.ZERO);
                    temp.setOnetozsnum(BigDecimal.ZERO);
                    temp.setTwotothreenum(BigDecimal.ZERO);
                    temp.setTwotozsnum(BigDecimal.ZERO);
                    temp.setThreetozsnum(BigDecimal.ZERO);
                    temp.setXfzsswbnum(BigDecimal.ZERO);
                    temp.setXfzssblnum(BigDecimal.ZERO);
                    temp.setDgjbbnfnum(BigDecimal.ZERO);
                    temp.setDgjlqnfnum(BigDecimal.ZERO);
                    temp.setDgjbxnfnum(BigDecimal.ZERO);
                    temp.setDgjbbzsnum(BigDecimal.ZERO);
                    temp.setDgjlqzsnum(BigDecimal.ZERO);
                    temp.setDgjbxzsnum(BigDecimal.ZERO);
                    temp.setDgjdzbnum(BigDecimal.ZERO);
                    temp.setPhtnum(BigDecimal.ZERO);
                    temp.setZsbinum(BigDecimal.ZERO);
                    temp.setDyjwbnum(BigDecimal.ZERO);
                    temp.setDyjblnum(BigDecimal.ZERO);
                    temp.setDybwbnum(BigDecimal.ZERO);
                    temp.setDybblnum(BigDecimal.ZERO);
                    temp.setDyzwbnum(BigDecimal.ZERO);
                    temp.setDyzblnum(BigDecimal.ZERO);
                    temp.setZswbdyjnum(BigDecimal.ZERO);
                    temp.setZsbldyjnum(BigDecimal.ZERO);
                    temp.setZswbdybnum(BigDecimal.ZERO);
                    temp.setZsbldybnum(BigDecimal.ZERO);
                    temp.setXkzje(BigDecimal.ZERO);
                    temp.setXfzje(BigDecimal.ZERO);
                    temp.setZnxzje(BigDecimal.ZERO);
                    temp.setDgjzje(BigDecimal.ZERO);
                    temp.setPhtzje(BigDecimal.ZERO);
                    temp.setZsbizje(BigDecimal.ZERO);
                    temp.setDyjzje(BigDecimal.ZERO);
                    temp.setDybzje(BigDecimal.ZERO);
                    temp.setDyzzje(BigDecimal.ZERO);
                    temp.setZnxdkysNum(BigDecimal.ZERO);
                    temp.setZnxdyjysNum(BigDecimal.ZERO);
                    temp.setWxcostnum(BigDecimal.ZERO);
                    temp.setSxfcostnum(BigDecimal.ZERO);
                    temp.setJfdknum(BigDecimal.ZERO);
                    temp.setSsjexj(BigDecimal.ZERO);
                    temp.setOnetotwonum(BigDecimal.ZERO);
                    temp.setJsxsenum(BigDecimal.ZERO);
                }
                // 计算提成
                ComputeDeductDTO computeDeductDTO = new ComputeDeductDTO() ;
                computeDeductDTO.setUserid( temp.getUserid());
                computeDeductDTO.setStartDate(queryDTO.getStartDate());
                computeDeductDTO.setEndDate(queryDTO.getEndDate());
                computeDeductDTO.setKtStartDate(queryDTO.getKtStartDate());
                computeDeductDTO.setKtEndDate(queryDTO.getKtEndDate());
                computeDeductDTO.setRemark(temp.getRemark());
                MonthDeductDTO monthDeductDTO = queryYwyDecutInfoNew(computeDeductDTO);

                if(monthDeductDTO != null ){
                    if(monthDeductDTO.getYfxxktcTotal() != null ){
                        temp.setXkdktc(monthDeductDTO.getYfxxktcTotal());
                    }else {
                        temp.setXkdktc(BigDecimal.ZERO);
                    }

                    if(monthDeductDTO.getYfxxftcTotal() != null ){
                        temp.setXfdktc(monthDeductDTO.getYfxxftcTotal());
                    }else {
                        temp.setXfdktc(BigDecimal.ZERO);
                    }

                    if(monthDeductDTO.getXsetcje() != null ){
                        temp.setXsetc(monthDeductDTO.getXsetcje());
                    }else {
                        temp.setXsetc(BigDecimal.ZERO);
                    }

                    if(monthDeductDTO.getDgjtcTotal() != null ){
                        temp.setDgjtc(monthDeductDTO.getDgjtcTotal());
                    }else {
                        temp.setDgjtc(BigDecimal.ZERO);
                    }

                    if(monthDeductDTO.getPhttcTotal() != null ){
                        temp.setPhttc(monthDeductDTO.getPhttcTotal());
                    }else {
                        temp.setPhttc(BigDecimal.ZERO);
                    }

                    if(monthDeductDTO.getZsbitcTotal() != null ){
                        temp.setZsbitc(monthDeductDTO.getZsbitcTotal());
                    }else {
                        temp.setZsbitc(BigDecimal.ZERO);
                    }

                    if(monthDeductDTO.getDyjtcTotal() != null ){
                        temp.setDyjtc(monthDeductDTO.getDyjtcTotal());
                    }else {
                        temp.setDyjtc(BigDecimal.ZERO);
                    }
                    if(monthDeductDTO.getXkjxse() != null ){
                        temp.setXkjxse(monthDeductDTO.getXkjxse());
                    }else {
                        temp.setXkjxse(BigDecimal.ZERO);
                    }

                    if(monthDeductDTO.getDyztcTotal() != null ){
                        temp.setDyztc(monthDeductDTO.getDyztcTotal());
                    }else {
                        temp.setDyztc(BigDecimal.ZERO);
                    }

                }else{
                    temp.setXkdktc(BigDecimal.ZERO);
                    temp.setXfdktc(BigDecimal.ZERO);
                    temp.setXsetc(BigDecimal.ZERO);
                    temp.setDgjtc(BigDecimal.ZERO);
                    temp.setPhttc(BigDecimal.ZERO);
                    temp.setZsbitc(BigDecimal.ZERO);
                    temp.setDyjtc(BigDecimal.ZERO);
                    temp.setDyztc(BigDecimal.ZERO);
                    temp.setXkjxse(BigDecimal.ZERO);
                }

            }
        }
        return employeeDeductDTOList;
    }

    @Override
    public List<SysDept> queryDeptments(SysDept sysDept) {

        List<SysDept>  list = sysDeptMapper.selectDeptList(sysDept);
        return list;
    }

    @Override
    public List<AreaDTO> queryProvinceList(AreaDTO areaDTO) {

        List<AreaDTO> list = achievementsMapper.queryProvinceList(areaDTO);

        return list;
    }

    @Override
    public List<AreaDTO> queryCityList(AreaDTO areaDTO) {
        List<AreaDTO> list = achievementsMapper.queryCityList(areaDTO);
        return list;
    }

    @Override
    public List<WxuserinfoDTO> queryWxuserList(WxuserinfoDTO wxuserinfoDTO) {

        List<WxuserinfoDTO> list = achievementsMapper.queryWxuserList(wxuserinfoDTO);
        return list;
    }

    @Override
    public int updateWxuserLxflag(WxuserinfoDTO wxuserinfoDTO) {
        int i = achievementsMapper.updateWxuserLxflag(wxuserinfoDTO);
        return i;
    }

    @Override
    public int updateAchievementsWeb(Achievements achievements) {
        return achievementsMapper.updateAchievements(achievements);
    }

    @Override
    @DataScope(deptAlias = "d", userAlias = "u")
    public List<Achievements> listAchDetail(Achievements achievements) throws ParseException {

        Integer ssyf = achievements.getSsyf();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        Date date = sdf.parse(String.valueOf(ssyf));
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        //获得本月第一天
        calendar.add(Calendar.MONTH, 0);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        //将小时至0
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        //将分钟至0
        calendar.set(Calendar.MINUTE, 0);
        //将秒至0
        calendar.set(Calendar.SECOND,0);
        //将毫秒至0
        calendar.set(Calendar.MILLISECOND, 0);

        Date firstDay = calendar.getTime();
        //将当前月加1；
        calendar.add(Calendar.MONTH, 1);
        //在当前月的下一月基础上减去1毫秒
        calendar.add(Calendar.MILLISECOND, -1);
        Date lastDay = calendar.getTime();

        achievements.setStartDate(firstDay);
        achievements.setEndDate(lastDay);

        List<Achievements> list = achievementsMapper.selectAchievementsList1(achievements);

        return list;
    }

    /**
     * 查询是否有驳回通知
     * @param achievements
     * @return
     */
    @Override
    public int queryBakcAchive(Achievements achievements) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();
        achievements.setUserId(user.getUserId());
        int i = achievementsMapper.queryUserBackAchiveNum(achievements);
        return i;
    }

    @Override
    public List<Achievements> examAchieList(Achievements achievements) throws ParseException {

        Integer ssyf = achievements.getSsyf();
        if(ssyf != null ){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
            Date date = sdf.parse(String.valueOf(ssyf));
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(date);
            //获得本月第一天
            calendar.add(Calendar.MONTH, 0);
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            //将小时至0
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            //将分钟至0
            calendar.set(Calendar.MINUTE, 0);
            //将秒至0
            calendar.set(Calendar.SECOND,0);
            //将毫秒至0
            calendar.set(Calendar.MILLISECOND, 0);

            Date firstDay = calendar.getTime();
            //将当前月加1；
            calendar.add(Calendar.MONTH, 1);
            //在当前月的下一月基础上减去1毫秒
            calendar.add(Calendar.MILLISECOND, -1);
            Date lastDay = calendar.getTime();

            achievements.setStartDate(firstDay);
            achievements.setEndDate(lastDay);
        }

        System.out.println("查询待审批列表");
        List<Achievements> list = achievementsMapper.selectAchievementsList2(achievements);

        return list;
    }

    @Override
    public int  examAchieListDai(Achievements achievements) throws ParseException {
        Integer ssyf = achievements.getSsyf();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        Date date = sdf.parse(String.valueOf(ssyf));
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        //获得本月第一天
        calendar.add(Calendar.MONTH, 0);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        //将小时至0
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        //将分钟至0
        calendar.set(Calendar.MINUTE, 0);
        //将秒至0
        calendar.set(Calendar.SECOND,0);
        //将毫秒至0
        calendar.set(Calendar.MILLISECOND, 0);

        Date firstDay = calendar.getTime();
        //将当前月加1；
        calendar.add(Calendar.MONTH, 1);
        //在当前月的下一月基础上减去1毫秒
        calendar.add(Calendar.MILLISECOND, -1);
        Date lastDay = calendar.getTime();

        achievements.setStartDate(firstDay);
        achievements.setEndDate(lastDay);
        System.out.println("查询待审核数量");
        int i =   achievementsMapper.selectAchievementsList3(achievements);

        return  i ;
    }



    // 根据achievements查询提成金额
    public Achievements queryTcjeByAchievements(Achievements temp){

        ComputeDeductDTO computeDeductDTO = new ComputeDeductDTO();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");
        computeDeductDTO.setXtczcflag( "1");

        computeDeductDTO.setYwlx(temp.getYwlx());
        computeDeductDTO.setKtlx(temp.getKtlx());
        computeDeductDTO.setDklx(temp.getDklx());
        computeDeductDTO.setDyjlx(temp.getDyjlx());
        computeDeductDTO.setDybtype(temp.getDybtype());
        computeDeductDTO.setPapertype(temp.getPapertype());
        computeDeductDTO.setDknum(temp.getDknum());
        computeDeductDTO.setZje(temp.getZje());
        computeDeductDTO.setJfdkje(temp.getJfdkje());
        if(temp.getDyjzsnum() != null){
            computeDeductDTO.setDyjzsnum(temp.getDyjzsnum());
        }

        computeDeductDTO.setDyjgmflag(temp.getDyjgmflag());
        computeDeductDTO.setDybgmflag(temp.getDybgmflag());
        computeDeductDTO.setDyzgmflag(temp.getDyzgmflag());
        computeDeductDTO.setDyjgmnum(temp.getDyjgmnum());
        computeDeductDTO.setDyjgmje(temp.getDyjgmje());
        computeDeductDTO.setDybgmnum(temp.getDybgmnum());
        computeDeductDTO.setDybgmje(temp.getDybgmje());
        computeDeductDTO.setDyzgmnum(temp.getDyzgmnum());
        computeDeductDTO.setDyzgmje(temp.getDyzgmje());
        computeDeductDTO.setZnxysdyjnum(temp.getZnxysdyjnum());
        computeDeductDTO.setZnxysnum(temp.getZnxysnum());

        String remark = temp.getRemark();
        if(StringUtils.isNotBlank(remark)){
            Integer i = remark.indexOf("年");
            if(i > 0){
                String num = remark.substring(0,i);
                computeDeductDTO.setGznx(Integer.valueOf(num));
            }
        }else {
            computeDeductDTO.setGznx(0);
        }

        // 云分销新开终生不送打印机
        if("1".equals(computeDeductDTO.getYwlx()) && "1".equals(computeDeductDTO.getKtlx()) && "2".equals(computeDeductDTO.getDklx()) ){
            BigDecimal dgje = BigDecimal.ZERO ;
            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje = computeDeductDTO.getZje() ;
                BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                if(jfdkje != null){
                    zje = zje.add(jfdkje);
                }
                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyjgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                    }
                }

                dgje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);

                if(dgje != null){
                    if(dgje.compareTo(new BigDecimal(1500)) > 0 && dgje.compareTo(new BigDecimal(2200)) < 0 ){
                        computeDeductDTO.setDgflag("1");
                    }else if(dgje.compareTo(new BigDecimal(1500)) <= 0 ){
                        computeDeductDTO.setDgflag("2");
                    }else{
                        computeDeductDTO.setDgflag("3");
                    }
                }
                computeDeductDTO.setDgje(dgje);
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }

        // 云分销续费终生不送打印机
        if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "1".equals(computeDeductDTO.getDklx()) ){
            BigDecimal dgje = BigDecimal.ZERO ;
            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje = computeDeductDTO.getZje() ;
                BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                if(jfdkje != null){
                    zje = zje.add(jfdkje);
                }
                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract((computeDeductDTO.getDyjgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract((computeDeductDTO.getDybgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract((computeDeductDTO.getDyzgmje()));
                    }
                }

                dgje = zje.divide((computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);
                if(dgje != null){
                    if(dgje.compareTo(new BigDecimal(1500)) > 0 && dgje.compareTo(new BigDecimal(2200)) < 0 ){
                        computeDeductDTO.setDgflag("1");
                    }else if(dgje.compareTo(new BigDecimal(1500)) <= 0 ){
                        computeDeductDTO.setDgflag("2");
                    }else{
                        computeDeductDTO.setDgflag("3");
                    }
                }
                computeDeductDTO.setDgje(dgje);
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }

        // 云分销新开终生送58打印机
        if("1".equals(computeDeductDTO.getYwlx()) && "1".equals(computeDeductDTO.getKtlx()) && "1".equals(computeDeductDTO.getDklx())){
            BigDecimal dgje = BigDecimal.ZERO ;
            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje = computeDeductDTO.getZje() ;
                BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                if(jfdkje != null){
                    zje = zje.add(jfdkje);
                }
                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract((computeDeductDTO.getDyjgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract((computeDeductDTO.getDybgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract((computeDeductDTO.getDyzgmje()));
                    }
                }

                if(computeDeductDTO.getDyjzsnum() != null ){
                    // 判断打印机赠送数量和端口数量是否一致，不一致的话，打印机数*2200 + 端口数乘以2400 是否等于总金额
                    if(computeDeductDTO.getDknum().compareTo(computeDeductDTO.getDyjzsnum()) == 0 ){
                        dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                    }else{
                        BigDecimal temp_zje = new BigDecimal(2200)
                                .multiply(computeDeductDTO.getDknum().subtract(computeDeductDTO.getDyjzsnum()))
                                .add(new BigDecimal(2400).multiply(computeDeductDTO.getDyjzsnum())) ;

                        if(temp_zje.compareTo(zje) == 0 ){
                            computeDeductDTO.setDgflag("3");
                            dgje = new BigDecimal(2400);
                        }else {
                            dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                        }
                    }
                }else{
                    dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                }

                if(dgje != null && dgje.compareTo(new BigDecimal(2400)) >= 0 ){
                    computeDeductDTO.setDgflag("3");
                }else{
                    if(dgje != null){
                        if(dgje.compareTo(new BigDecimal(1500)) > 0 ){
                            computeDeductDTO.setDgflag("1");
                        }else {
                            computeDeductDTO.setDgflag("2");
                        }
                    }
                }


                computeDeductDTO.setDgje(dgje);
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }

        // 云分销续费终生送58打印机
        if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "11".equals(computeDeductDTO.getDklx())){
            BigDecimal dgje = BigDecimal.ZERO ;
            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje = computeDeductDTO.getZje() ;
                BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                if(jfdkje != null){
                    zje = zje.add(jfdkje);
                }
                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyjgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                    }
                }


                if(computeDeductDTO.getDyjzsnum() != null ){
                    // 判断打印机赠送数量和端口数量是否一致，不一致的话，打印机数*2200 + 端口数乘以2400 是否等于总金额
                    if(computeDeductDTO.getDknum().compareTo(computeDeductDTO.getDyjzsnum()) == 0 ){
                        dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                    }else{
                        BigDecimal temp_zje = new BigDecimal(2200)
                                .multiply(computeDeductDTO.getDknum().subtract(computeDeductDTO.getDyjzsnum()))
                                .add(new BigDecimal(2400).multiply(computeDeductDTO.getDyjzsnum())) ;

                        if(temp_zje.compareTo(zje) == 0 ){
                            computeDeductDTO.setDgflag("3");
                            dgje = new BigDecimal(2400);
                        }else {
                            dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                        }
                    }
                }else{
                    dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                }

                if(dgje != null && dgje.compareTo(new BigDecimal(2400)) >= 0 ){
                    computeDeductDTO.setDgflag("3");
                }else{
                    if(dgje != null){
                        if(dgje.compareTo(new BigDecimal(1500)) > 0 ){
                            computeDeductDTO.setDgflag("1");
                        }else {
                            computeDeductDTO.setDgflag("2");
                        }
                    }
                }


                computeDeductDTO.setDgje(dgje);
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }

        // 云分销新开终生送80打印机
        if("1".equals(computeDeductDTO.getYwlx()) && "1".equals(computeDeductDTO.getKtlx()) && "6".equals(computeDeductDTO.getDklx()) ){
            BigDecimal dgje = BigDecimal.ZERO ;
            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje = computeDeductDTO.getZje() ;
                BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                if(jfdkje != null){
                    zje = zje.add(jfdkje);
                }
                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract(computeDeductDTO.getDyjgmje());
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract(computeDeductDTO.getDybgmje());
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract(computeDeductDTO.getDyzgmje());
                    }
                }

                if(computeDeductDTO.getDyjzsnum() != null ){
                    // 判断打印机赠送数量和端口数量是否一致，不一致的话，打印机数*2200 + 端口数乘以2400 是否等于总金额
                    if(computeDeductDTO.getDknum().compareTo(computeDeductDTO.getDyjzsnum()) == 0 ){
                        dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                    }else{
                        BigDecimal temp_zje = new BigDecimal(2200)
                                .multiply(computeDeductDTO.getDknum().subtract(computeDeductDTO.getDyjzsnum()))
                                .add(new BigDecimal(2400).multiply(computeDeductDTO.getDyjzsnum())) ;

                        if(temp_zje.compareTo(zje) == 0 ){
                            computeDeductDTO.setDgflag("3");
                            dgje = new BigDecimal(2400);
                        }else {
                            dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                        }
                    }
                }else{
                    dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                }

                if(dgje != null && dgje.compareTo(new BigDecimal(2400)) >= 0 ){
                    computeDeductDTO.setDgflag("3");
                }else{
                    if(dgje != null){
                        if(dgje.compareTo(new BigDecimal(1500)) > 0 ){
                            computeDeductDTO.setDgflag("1");
                        }else {
                            computeDeductDTO.setDgflag("2");
                        }
                    }
                }


                computeDeductDTO.setDgje(dgje);
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }

        // 云分销新开终生送80打印机
        if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "12".equals(computeDeductDTO.getDklx()) ){
            BigDecimal dgje = BigDecimal.ZERO ;
            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje = computeDeductDTO.getZje() ;
                BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                if(jfdkje != null){
                    zje = zje.add(jfdkje);
                }
                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyjgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                    }
                }

                if(computeDeductDTO.getDyjzsnum() != null ){
                    // 判断打印机赠送数量和端口数量是否一致，不一致的话，打印机数*2200 + 端口数乘以2400 是否等于总金额
                    if(computeDeductDTO.getDknum().compareTo(computeDeductDTO.getDyjzsnum()) == 0 ){
                        dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                    }else{
                        BigDecimal temp_zje = new BigDecimal(2200)
                                .multiply(computeDeductDTO.getDknum().subtract(computeDeductDTO.getDyjzsnum()))
                                .add(new BigDecimal(2400).multiply(computeDeductDTO.getDyjzsnum())) ;

                        if(temp_zje.compareTo(zje) == 0 ){
                            computeDeductDTO.setDgflag("3");
                            dgje = new BigDecimal(2400);
                        }else {
                            dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                        }
                    }
                }else{
                    dgje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                }

                if(dgje != null && dgje.compareTo(new BigDecimal(2400)) >= 0 ){
                    computeDeductDTO.setDgflag("3");
                }else{
                    if(dgje != null){
                        if(dgje.compareTo(new BigDecimal(1500)) > 0 ){
                            computeDeductDTO.setDgflag("1");
                        }else {
                            computeDeductDTO.setDgflag("2");
                        }
                    }
                }

                computeDeductDTO.setDgje(dgje);
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }

        // 云分销转年限一年转终生

        if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "7".equals(computeDeductDTO.getDklx()) ){
            BigDecimal dgje = BigDecimal.ZERO ;
            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje = BigDecimal.ZERO ;
                BigDecimal ynnum = BigDecimal.ZERO ;
                if(computeDeductDTO.getZnxysnum() != null){
                    zje  = computeDeductDTO.getZje().add(computeDeductDTO.getZnxysnum());
                    ynnum = computeDeductDTO.getZnxysnum().divide(computeDeductDTO.getDknum(),0,BigDecimal.ROUND_HALF_UP);
                }

                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract(computeDeductDTO.getDyjgmje());
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract(computeDeductDTO.getDybgmje());
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract(computeDeductDTO.getDyzgmje());
                    }
                }


                BigDecimal pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);

                       /* 终生不再计算打印机
                       if(computeDeductDTO.getZnxysdyjnum() != null){
                            BigDecimal[] results = computeDeductDTO.getZnxysdyjnum().divideAndRemainder(BigDecimal.valueOf(310));
                            BigDecimal[] results1 = computeDeductDTO.getZnxysdyjnum().divideAndRemainder(BigDecimal.valueOf(430));

                            if(results[1].compareTo(BigDecimal.ZERO) == 0 ){
                                computeDeductDTO.setDyjtclx("58");
                                computeDeductDTO.setZnxysjgs(results[0]);
                                if(results[0].compareTo(BigDecimal.ZERO) > 0 ){
                                    dgje = pjje.add(new BigDecimal(122));
                                }else{
                                    dgje = pjje ;
                                }
                                dgje = pjje ;
                            }else{
                                computeDeductDTO.setDyjtclx("80");
                                computeDeductDTO.setZnxysjgs(results1[0]);
                                if(results1[0].compareTo(BigDecimal.ZERO) > 0 ){
                                    dgje = pjje.add(new BigDecimal(142));
                                }else{
                                    dgje = pjje ;
                                }
                            }
                        }*/


                if(pjje != null){
                    if(pjje.compareTo(new BigDecimal(2200)) >= 0 ){
                        computeDeductDTO.setDgflag("1");
                        if(ynnum.compareTo(new BigDecimal(600)) >= 0 ){
                            computeDeductDTO.setZcflag("1"); //2022年新政策，一年提成150
                        }else{
                            computeDeductDTO.setZcflag("2"); // 2021年老政策，一年提成50
                        }
                    }else {
                        computeDeductDTO.setDgflag("2");
                        if(ynnum.compareTo(new BigDecimal(600)) >= 0 ){
                            computeDeductDTO.setZcflag("1"); //2022年新政策，一年提成150
                        }else{
                            computeDeductDTO.setZcflag("2"); // 2021年老政策，一年提成50
                        }
                    }
                }
                computeDeductDTO.setDgje(pjje);
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }

        // 云分销续费二年转终生
        if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "9".equals(computeDeductDTO.getDklx()) ){
            BigDecimal dgje = BigDecimal.ZERO ;
            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje = BigDecimal.ZERO;
                BigDecimal ennum = BigDecimal.ZERO;
                if(computeDeductDTO.getZnxysnum() != null){
                    zje  = computeDeductDTO.getZje().add(computeDeductDTO.getZnxysnum());
                    ennum = computeDeductDTO.getZnxysnum().divide(computeDeductDTO.getDknum(),0,BigDecimal.ROUND_HALF_UP);
                }
                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract(computeDeductDTO.getDyjgmje());
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract(computeDeductDTO.getDybgmje());
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract(computeDeductDTO.getDyzgmje());
                    }
                }

                BigDecimal pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);

                if(pjje != null){
                    if(pjje.compareTo(new BigDecimal(2200)) >= 0 ){
                        computeDeductDTO.setDgflag("1");
                        // 二年1200
                        if(ennum.compareTo(new BigDecimal(1200)) >= 0 ){
                            computeDeductDTO.setZcflag("1");
                        }else {
                            // 二年688
                            computeDeductDTO.setZcflag("2");
                        }

                    }else {
                        computeDeductDTO.setDgflag("2");

                        if(ennum.compareTo(new BigDecimal(1200)) >= 0 ){
                            computeDeductDTO.setZcflag("1");
                        }else {
                            // 二年688
                            computeDeductDTO.setZcflag("2");
                        }

                    }
                }
                computeDeductDTO.setDgje(pjje);
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }

        // 云分销续费三年转终生
        if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "10".equals(computeDeductDTO.getDklx()) ){
            BigDecimal dgje = BigDecimal.ZERO ;
            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje = BigDecimal.ZERO ;
                BigDecimal snnum = BigDecimal.ZERO ;
                if(computeDeductDTO.getZnxysnum() != null){
                    zje  = computeDeductDTO.getZje().add(computeDeductDTO.getZnxysnum());
                    snnum = computeDeductDTO.getZnxysnum().divide(computeDeductDTO.getDknum(),0,BigDecimal.ROUND_HALF_UP);
                }
                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract(computeDeductDTO.getDyjgmje());
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                    }
                }

                BigDecimal pjje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);

                if(pjje != null){
                    if(pjje.compareTo(new BigDecimal(2200)) >= 0 ){
                        computeDeductDTO.setDgflag("1");
                        // 三年1800
                        if(snnum.compareTo(new BigDecimal(1800)) >= 0 ){
                            computeDeductDTO.setZcflag("1");
                        }else {
                            // 三年988
                            computeDeductDTO.setZcflag("2");
                        }
                    }else {
                        computeDeductDTO.setDgflag("2");

                        // 三年1800
                        if(snnum.compareTo(new BigDecimal(1800)) >= 0 ){
                            computeDeductDTO.setZcflag("1");
                        }else {
                            // 三年988
                            computeDeductDTO.setZcflag("2");
                        }
                    }
                }
                computeDeductDTO.setDgje(pjje);
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }

        // 云分销续费一年转终生送58打印机
        if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) &&  "13".equals(computeDeductDTO.getDklx()) ){
            BigDecimal dgje = BigDecimal.ZERO ;
            BigDecimal ynnum = BigDecimal.ZERO ;
            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje = BigDecimal.ZERO ;
                if(computeDeductDTO.getZnxysnum() != null){
                    zje  = computeDeductDTO.getZje().add(computeDeductDTO.getZnxysnum());
                    ynnum = computeDeductDTO.getZnxysnum().divide(computeDeductDTO.getDknum(),0,BigDecimal.ROUND_HALF_UP);
                }

                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract(computeDeductDTO.getDyjgmje());
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                    }
                }

                if(computeDeductDTO.getZnxysdyjnum() != null){
                    zje = zje.add(computeDeductDTO.getZnxysdyjnum());
                }


                if(computeDeductDTO.getZnxysdyjnum() != null){
                    BigDecimal dyjgs = computeDeductDTO.getZnxysdyjnum().divide(BigDecimal.valueOf(310),0,BigDecimal.ROUND_HALF_UP);
                    // BigDecimal[] results1 = computeDeductDTO.getZnxysdyjnum().divideAndRemainder(BigDecimal.valueOf(430));
                    computeDeductDTO.setDyjtclx("58");
                    if(dyjgs != null){
                        computeDeductDTO.setZnxysjgs(dyjgs);
                    }else {
                        computeDeductDTO.setZnxysjgs(BigDecimal.ZERO);
                    }
                }


                BigDecimal pjje = BigDecimal.ZERO ;
                if(computeDeductDTO.getDyjzsnum() != null ){
                    // 判断打印机赠送数量和端口数量是否一致，不一致的话，打印机数*2200 + 端口数乘以2400 是否等于总金额
                    if(computeDeductDTO.getDknum().compareTo(computeDeductDTO.getDyjzsnum()) == 0 ){
                        pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                    }else{
                        BigDecimal temp_zje = new BigDecimal(2200)
                                .multiply(computeDeductDTO.getDknum().subtract(computeDeductDTO.getDyjzsnum()))
                                .add(new BigDecimal(2400).multiply(computeDeductDTO.getDyjzsnum())) ;

                        if(temp_zje.compareTo(zje) == 0 ){
                            computeDeductDTO.setDgflag("3");
                            pjje = new BigDecimal(2400);
                        }else {
                            pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                        }
                    }
                }else{
                    pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                }

                if(pjje != null){
                    if(pjje.compareTo(new BigDecimal(2400)) >= 0 ){
                        computeDeductDTO.setDgflag("1");

                        if(ynnum.compareTo(new BigDecimal(600)) >= 0 ){
                            computeDeductDTO.setZcflag("1");
                        }else {
                            // 三年988
                            computeDeductDTO.setZcflag("2");
                        }

                    }else {
                        computeDeductDTO.setDgflag("2");

                        if(ynnum.compareTo(new BigDecimal(600)) >= 0 ){
                            computeDeductDTO.setZcflag("1");
                        }else {
                            // 三年988
                            computeDeductDTO.setZcflag("2");
                        }
                    }
                }
                computeDeductDTO.setDgje(pjje);
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }

        // 云分销续费一年转终生送80打印机
        if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "14".equals(computeDeductDTO.getDklx()) ){
            BigDecimal dgje = BigDecimal.ZERO ;
            BigDecimal ynnum = BigDecimal.ZERO ;
            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje = BigDecimal.ZERO ;
                if(computeDeductDTO.getZnxysnum() != null){
                    zje  = computeDeductDTO.getZje().add(computeDeductDTO.getZnxysnum());
                    ynnum = computeDeductDTO.getZnxysnum().divide(computeDeductDTO.getDknum(),0,BigDecimal.ROUND_HALF_UP);
                }

                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract(computeDeductDTO.getDyjgmje());
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract(computeDeductDTO.getDybgmje());
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract(computeDeductDTO.getDyzgmje());
                    }
                }

                if(computeDeductDTO.getZnxysdyjnum() != null){
                    zje = zje.add(computeDeductDTO.getZnxysdyjnum());
                }

                if(computeDeductDTO.getZnxysdyjnum() != null){
                    BigDecimal dyjgs = computeDeductDTO.getZnxysdyjnum().divide(BigDecimal.valueOf(430),0,BigDecimal.ROUND_HALF_UP);
                    // BigDecimal[] results1 = computeDeductDTO.getZnxysdyjnum().divideAndRemainder(BigDecimal.valueOf(430));
                    computeDeductDTO.setDyjtclx("80");
                    if(dyjgs != null){
                        computeDeductDTO.setZnxysjgs(dyjgs);
                    }else {
                        computeDeductDTO.setZnxysjgs(BigDecimal.ZERO);
                    }
                }

                BigDecimal pjje = BigDecimal.ZERO ;
                if(computeDeductDTO.getDyjzsnum() != null ){
                    // 判断打印机赠送数量和端口数量是否一致，不一致的话，打印机数*2200 + 端口数乘以2400 是否等于总金额
                    if(computeDeductDTO.getDknum().compareTo(computeDeductDTO.getDyjzsnum()) == 0 ){
                        pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                    }else{
                        BigDecimal temp_zje = new BigDecimal(2200 )
                                .multiply(computeDeductDTO.getDknum().subtract(computeDeductDTO.getDyjzsnum()))
                                .add(new BigDecimal(2400).multiply(computeDeductDTO.getDyjzsnum())) ;

                        if(temp_zje.compareTo(zje) == 0 ){
                            computeDeductDTO.setDgflag("3");
                            pjje = new BigDecimal(2400);
                        }else {
                            pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                        }
                    }
                }else{
                    pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                }

                if(pjje != null){
                    if(pjje.compareTo(new BigDecimal(2400)) >= 0 ){
                        computeDeductDTO.setDgflag("1");

                        if(ynnum.compareTo(new BigDecimal(600)) >= 0 ){
                            computeDeductDTO.setZcflag("1");
                        }else {
                            // 三年988
                            computeDeductDTO.setZcflag("2");

                            if(ynnum.compareTo(new BigDecimal(600)) >= 0 ){
                                computeDeductDTO.setZcflag("1");
                            }else {
                                // 三年988
                                computeDeductDTO.setZcflag("2");
                            }
                        }
                    }else {
                        computeDeductDTO.setDgflag("2");

                        if(ynnum.compareTo(new BigDecimal(600)) >= 0 ){
                            computeDeductDTO.setZcflag("1");
                        }else {
                            // 三年988
                            computeDeductDTO.setZcflag("2");

                            if(ynnum.compareTo(new BigDecimal(600)) >= 0 ){
                                computeDeductDTO.setZcflag("1");
                            }else {
                                // 三年988
                                computeDeductDTO.setZcflag("2");
                            }
                        }

                    }
                }
                computeDeductDTO.setDgje(pjje);
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }

        // 云分销续费二年转终生送58打印机
        if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "15".equals(computeDeductDTO.getDklx())){
            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje = BigDecimal.ZERO ;
                if(computeDeductDTO.getZnxysnum() != null){
                    zje  = computeDeductDTO.getZje().add(computeDeductDTO.getZnxysnum());
                    BigDecimal ysdgje = computeDeductDTO.getZnxysnum().divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                    String tcfalg = "1";
                    if(ysdgje != null && ysdgje.compareTo(new BigDecimal(1200)) >= 0 ){
                        tcfalg = "1"; // 2022年新政策
                    }else{
                        tcfalg = "2"; // 2021年老政策
                    }
                    computeDeductDTO.setTcflag(tcfalg);
                }

                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyjgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                    }
                }

                if(computeDeductDTO.getZnxysdyjnum() != null){
                    zje = zje.add(computeDeductDTO.getZnxysdyjnum());
                }

                if(computeDeductDTO.getZnxysdyjnum() != null){
                    BigDecimal dyjgs = computeDeductDTO.getZnxysdyjnum().divide(BigDecimal.valueOf(310),0,BigDecimal.ROUND_HALF_UP);
                    computeDeductDTO.setDyjtclx("58");
                    if(dyjgs != null){
                        computeDeductDTO.setZnxysjgs(dyjgs);
                    }else {
                        computeDeductDTO.setZnxysjgs(BigDecimal.ZERO);
                    }
                }

                BigDecimal pjje = BigDecimal.ZERO ;
                if(computeDeductDTO.getDyjzsnum() != null ){
                    // 判断打印机赠送数量和端口数量是否一致，不一致的话，打印机数*2200 + 端口数乘以2400 是否等于总金额
                    if(computeDeductDTO.getDknum().compareTo(computeDeductDTO.getDyjzsnum()) == 0 ){
                        pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                    }else{
                        BigDecimal temp_zje = new BigDecimal(2200)
                                .multiply(computeDeductDTO.getDknum().subtract(computeDeductDTO.getDyjzsnum()))
                                .add(new BigDecimal(2400).multiply(computeDeductDTO.getDyjzsnum())) ;

                        if(temp_zje.compareTo(zje) == 0 ){
                            computeDeductDTO.setDgflag("3");
                            pjje = new BigDecimal(2400);
                        }else {
                            pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                        }
                    }
                }else{
                    pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                }

                if(pjje != null){
                    if(pjje.compareTo(new BigDecimal(2400)) >= 0 ){
                        computeDeductDTO.setDgflag("1");
                    }else {
                        computeDeductDTO.setDgflag("2");
                    }
                }
                computeDeductDTO.setDgje(pjje);
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }

        // 云分销续费二年转终生送80打印机
        if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "16".equals(computeDeductDTO.getDklx()) ){
            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje = BigDecimal.ZERO ;
                if(computeDeductDTO.getZnxysnum() != null){
                    zje  = computeDeductDTO.getZje().add(computeDeductDTO.getZnxysnum());

                    BigDecimal ysdgje = computeDeductDTO.getZnxysnum().divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                    String tcfalg = "1";
                    if(ysdgje != null && ysdgje.compareTo(new BigDecimal(1200)) >= 0 ){
                        tcfalg = "1";
                    }else{
                        tcfalg = "2";
                    }
                    computeDeductDTO.setTcflag(tcfalg);

                }

                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyjgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                    }
                }

                if(computeDeductDTO.getZnxysdyjnum() != null){
                    zje = zje.add(computeDeductDTO.getZnxysdyjnum());
                }

                if(computeDeductDTO.getZnxysdyjnum() != null){
                    BigDecimal dyjgs = computeDeductDTO.getZnxysdyjnum().divide(BigDecimal.valueOf(430),0,BigDecimal.ROUND_HALF_UP);
                    // BigDecimal[] results1 = computeDeductDTO.getZnxysdyjnum().divideAndRemainder(BigDecimal.valueOf(430));
                    computeDeductDTO.setDyjtclx("80");
                    if(dyjgs != null){
                        computeDeductDTO.setZnxysjgs(dyjgs);
                    }else {
                        computeDeductDTO.setZnxysjgs(BigDecimal.ZERO);
                    }
                }

                BigDecimal pjje = BigDecimal.ZERO ;
                if(computeDeductDTO.getDyjzsnum() != null ){
                    // 判断打印机赠送数量和端口数量是否一致，不一致的话，打印机数*2200 + 端口数乘以2400 是否等于总金额
                    if(computeDeductDTO.getDknum().compareTo(computeDeductDTO.getDyjzsnum()) == 0 ){
                        pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                    }else{
                        BigDecimal temp_zje = new BigDecimal(2200)
                                .multiply(computeDeductDTO.getDknum().subtract(computeDeductDTO.getDyjzsnum()))
                                .add(new BigDecimal(2400).multiply(computeDeductDTO.getDyjzsnum())) ;

                        if(temp_zje.compareTo(zje) == 0 ){
                            computeDeductDTO.setDgflag("3");
                            pjje = new BigDecimal(2400);
                        }else {
                            pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                        }
                    }
                }else{
                    pjje = zje.divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                }


                if(pjje != null){
                    if(pjje.compareTo(new BigDecimal(2400)) >= 0 ){
                        computeDeductDTO.setDgflag("1");
                    }else {
                        computeDeductDTO.setDgflag("2");
                    }
                }
                computeDeductDTO.setDgje(pjje);
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }

        // 云分销续费三年转终生送58打印机
        if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "17".equals(computeDeductDTO.getDklx()) ){

            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje = BigDecimal.ZERO ;
                if(computeDeductDTO.getZnxysnum() != null){
                    zje  = computeDeductDTO.getZje().add(computeDeductDTO.getZnxysnum());
                    BigDecimal ysdgje = computeDeductDTO.getZnxysnum().divide(computeDeductDTO.getDknum(),2,BigDecimal.ROUND_HALF_UP);
                    String tcfalg = "1";
                    if(ysdgje != null && ysdgje.compareTo(new BigDecimal(1800)) >= 0 ){
                        tcfalg = "1";
                    }else{
                        tcfalg = "2";
                    }
                    computeDeductDTO.setTcflag(tcfalg);
                }

                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract(computeDeductDTO.getDyjgmje());
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract(computeDeductDTO.getDybgmje());
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                    }
                }

                if(computeDeductDTO.getZnxysdyjnum() != null){
                    zje = zje.add(computeDeductDTO.getZnxysdyjnum());
                }

                if(computeDeductDTO.getZnxysdyjnum() != null){
                    BigDecimal dyjgs = computeDeductDTO.getZnxysdyjnum().divide(BigDecimal.valueOf(310),0,BigDecimal.ROUND_HALF_UP);
                    computeDeductDTO.setDyjtclx("58");
                    if(dyjgs != null){
                        computeDeductDTO.setZnxysjgs(dyjgs);
                    }else {
                        computeDeductDTO.setZnxysjgs(BigDecimal.ZERO);
                    }
                }


                BigDecimal pjje = BigDecimal.ZERO ;
                if(computeDeductDTO.getDyjzsnum() != null ){
                    // 判断打印机赠送数量和端口数量是否一致，不一致的话，打印机数*2200 + 端口数乘以2400 是否等于总金额
                    if( (computeDeductDTO.getDknum()).compareTo(computeDeductDTO.getDyjzsnum()) == 0 ){
                        pjje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);
                    }else{
                        BigDecimal temp_zje = new BigDecimal(2200)
                                .multiply( (computeDeductDTO.getDknum()).subtract(computeDeductDTO.getDyjzsnum()))
                                .add(new BigDecimal(2400).multiply(computeDeductDTO.getDyjzsnum())) ;

                        if(temp_zje.compareTo(zje) == 0 ){
                            computeDeductDTO.setDgflag("3");
                            pjje = new BigDecimal(2400);
                        }else {
                            pjje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);
                        }
                    }
                }else{
                    pjje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);
                }


                if(pjje != null){
                    if(pjje.compareTo(new BigDecimal(2400)) >= 0 ){
                        computeDeductDTO.setDgflag("1");
                    }else {
                        computeDeductDTO.setDgflag("2");
                    }
                }
                computeDeductDTO.setDgje(pjje);
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }

        // 云分销续费二年转终生送80打印机
        if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "18".equals(computeDeductDTO.getDklx()) ){
            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje = BigDecimal.ZERO ;
                if(computeDeductDTO.getZnxysnum() != null){
                    zje  = computeDeductDTO.getZje().add(computeDeductDTO.getZnxysnum());

                    BigDecimal ysdgje = computeDeductDTO.getZnxysnum().divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);
                    String tcfalg = "1";
                    if(ysdgje != null && ysdgje.compareTo(new BigDecimal(1800)) >= 0 ){
                        tcfalg = "1";
                    }else{
                        tcfalg = "2";
                    }
                    computeDeductDTO.setTcflag(tcfalg);
                }

                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyjgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                    }
                }

                if(computeDeductDTO.getZnxysdyjnum() != null){
                    zje = zje.add(computeDeductDTO.getZnxysdyjnum());
                }

                if(computeDeductDTO.getZnxysdyjnum() != null){
                    BigDecimal dyjgs = computeDeductDTO.getZnxysdyjnum().divide(BigDecimal.valueOf(430),0,BigDecimal.ROUND_HALF_UP);
                    computeDeductDTO.setDyjtclx("80");
                    if(dyjgs != null){
                        computeDeductDTO.setZnxysjgs(dyjgs);
                    }else {
                        computeDeductDTO.setZnxysjgs(BigDecimal.ZERO);
                    }
                }

                BigDecimal pjje = BigDecimal.ZERO ;
                if(computeDeductDTO.getDyjzsnum() != null ){
                    // 判断打印机赠送数量和端口数量是否一致，不一致的话，打印机数*2200 + 端口数乘以2400 是否等于总金额
                    if( (computeDeductDTO.getDknum()).compareTo(computeDeductDTO.getDyjzsnum()) == 0 ){
                        pjje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);
                    }else{
                        BigDecimal temp_zje = new BigDecimal(2200)
                                .multiply( (computeDeductDTO.getDknum()).subtract(computeDeductDTO.getDyjzsnum()))
                                .add(new BigDecimal(2400).multiply(computeDeductDTO.getDyjzsnum())) ;

                        if(temp_zje.compareTo(zje) == 0 ){
                            computeDeductDTO.setDgflag("3");
                            pjje = new BigDecimal(2400);
                        }else {
                            pjje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);
                        }
                    }
                }else{
                    pjje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);
                }

                if(pjje != null){
                    if(pjje.compareTo(new BigDecimal(2400)) >= 0 ){
                        computeDeductDTO.setDgflag("1");
                    }else {
                        computeDeductDTO.setDgflag("2");
                    }
                }
                computeDeductDTO.setDgje(pjje);
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }

        //云分销新开一年
        if("1".equals(computeDeductDTO.getYwlx()) && "1".equals(computeDeductDTO.getKtlx()) && "5".equals(computeDeductDTO.getDklx())){
            BigDecimal dgje = BigDecimal.ZERO ;
            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje  = computeDeductDTO.getZje();
                BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                if(jfdkje != null){
                    zje = zje.add(jfdkje);
                }
                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyjgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                    }
                }

                dgje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);

                if(dgje != null){
                    if(dgje.compareTo(new BigDecimal(600)) >= 0 ){
                        computeDeductDTO.setDgflag("1");
                    }else {
                        computeDeductDTO.setDgflag("2");
                    }
                }
                computeDeductDTO.setDgje(dgje);
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }


        //云分销续费一年
        if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "4".equals(computeDeductDTO.getDklx())){
            BigDecimal dgje = BigDecimal.ZERO ;
            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje  = computeDeductDTO.getZje();
                BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                if(jfdkje != null){
                    zje = zje.add(jfdkje);
                }
                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyjgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                    }
                }

                dgje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);

                if(dgje != null){
                    if(dgje.compareTo(new BigDecimal(600)) >= 0 ){
                        computeDeductDTO.setDgflag("1");
                    }else {
                        computeDeductDTO.setDgflag("2");
                    }
                }
                computeDeductDTO.setDgje( dgje );
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }

        // 云分销新开两年
        if("1".equals(computeDeductDTO.getYwlx()) && "1".equals(computeDeductDTO.getKtlx()) && "4".equals(computeDeductDTO.getDklx()) ){
            BigDecimal dgje = BigDecimal.ZERO ;
            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje  = computeDeductDTO.getZje();
                BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                if(jfdkje != null){
                    zje = zje.add(jfdkje);
                }
                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyjgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                    }
                }

                dgje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);

                if(dgje != null){
                    if(dgje.compareTo(new BigDecimal(688)) >= 0 && dgje.compareTo(new BigDecimal(1200)) < 0 ){
                        computeDeductDTO.setDgflag("1");
                    }else if(dgje.compareTo(new BigDecimal(688)) < 0 ){
                        computeDeductDTO.setDgflag("2");
                    }else {
                        computeDeductDTO.setDgflag("3");
                    }
                }
                computeDeductDTO.setDgje(dgje);
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }

        // 云分销续费两年
        if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "3".equals(computeDeductDTO.getDklx()) ){
            BigDecimal dgje = BigDecimal.ZERO ;
            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje  = computeDeductDTO.getZje();
                BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                if(jfdkje != null){
                    zje = zje.add(jfdkje);
                }
                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyjgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                    }
                }

                dgje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);

                if(dgje != null){
                    if( dgje.compareTo( new BigDecimal(1200)) < 0 ){
                        computeDeductDTO.setDgflag("2");
                    }else {
                        computeDeductDTO.setDgflag("1");
                    }
                }
                computeDeductDTO.setDgje(dgje);
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }

        // 云分销新开三年
        if("1".equals(computeDeductDTO.getYwlx()) && "1".equals(computeDeductDTO.getKtlx()) && "3".equals(computeDeductDTO.getDklx()) ){
            BigDecimal dgje = BigDecimal.ZERO ;
            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje  = computeDeductDTO.getZje();
                BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                if(jfdkje != null){
                    zje = zje.add(jfdkje);
                }
                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyjgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                    }
                }

                dgje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);

                if(dgje != null){
                    if(dgje.compareTo(new BigDecimal(988)) >= 0 && dgje.compareTo(new BigDecimal(1800)) < 0 ){
                        computeDeductDTO.setDgflag("1");
                    }else if(dgje.compareTo(new BigDecimal(988)) < 0 ){
                        computeDeductDTO.setDgflag("2");
                    }else{
                        computeDeductDTO.setDgflag("3");
                    }
                }
                computeDeductDTO.setDgje(dgje);
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }

        // 云分销续费三年
        if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "2".equals(computeDeductDTO.getDklx()) ){
            BigDecimal dgje = BigDecimal.ZERO ;
            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje  = computeDeductDTO.getZje();
                BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                if(jfdkje != null){
                    zje = zje.add(jfdkje);
                }
                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyjgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                    }
                }

                dgje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);

                if(dgje != null){
                    if(dgje.compareTo(new BigDecimal(988)) >= 0 && dgje.compareTo(new BigDecimal(1800)) < 0 ){
                        computeDeductDTO.setDgflag("1");
                    }else if(dgje.compareTo(new BigDecimal(988)) < 0 ){
                        computeDeductDTO.setDgflag("2");
                    }else{
                        computeDeductDTO.setDgflag("3");
                    }
                }
                computeDeductDTO.setDgje(dgje);
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }



        // 云分销新开,买二送一
        if("1".equals(computeDeductDTO.getYwlx()) && "1".equals(computeDeductDTO.getKtlx()) && "7".equals(computeDeductDTO.getDklx()) ){
            BigDecimal dgje = BigDecimal.ZERO ;
            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje  = computeDeductDTO.getZje();
                BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                if(jfdkje != null){
                    zje = zje.add(jfdkje);
                }
                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyjgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                    }
                }

                dgje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);

                if(dgje != null){
                    if(dgje.compareTo(new BigDecimal(1200)) >= 0){
                        computeDeductDTO.setDgflag("1");
                    }else {
                        computeDeductDTO.setDgflag("2");
                    }
                }
                computeDeductDTO.setDgje(dgje);
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }


        // 云分销新开,买三送二
        if("1".equals(computeDeductDTO.getYwlx()) && "1".equals(computeDeductDTO.getKtlx()) && "8".equals(computeDeductDTO.getDklx()) ){
            BigDecimal dgje = BigDecimal.ZERO ;
            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje  = computeDeductDTO.getZje();
                BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                if(jfdkje != null){
                    zje = zje.add(jfdkje);
                }
                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyjgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                    }
                }

                dgje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);

                if(dgje != null){
                    if(dgje.compareTo(new BigDecimal(1800)) >= 0){
                        computeDeductDTO.setDgflag("1");
                    }else {
                        computeDeductDTO.setDgflag("2");
                    }
                }
                computeDeductDTO.setDgje(dgje);
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }


        // 云分销续费，买二送一
        if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "19".equals(computeDeductDTO.getDklx()) ){
            BigDecimal dgje = BigDecimal.ZERO ;
            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje  = computeDeductDTO.getZje();
                BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                if(jfdkje != null){
                    zje = zje.add(jfdkje);
                }
                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyjgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                    }
                }

                dgje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);

                if(dgje != null){
                    if(dgje.compareTo(new BigDecimal(1200)) >= 0){
                        computeDeductDTO.setDgflag("1");
                    }else {
                        computeDeductDTO.setDgflag("2");
                    }
                }
                computeDeductDTO.setDgje(dgje);
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }


        // 云分销续费，买三送二
        if("1".equals(computeDeductDTO.getYwlx()) && "2".equals(computeDeductDTO.getKtlx()) && "20".equals(computeDeductDTO.getDklx()) ){
            BigDecimal dgje = BigDecimal.ZERO ;
            if(computeDeductDTO.getZje() != null && computeDeductDTO.getDknum() != null && computeDeductDTO.getDknum().compareTo(BigDecimal.ZERO) > 0 ){
                BigDecimal zje  = computeDeductDTO.getZje();
                BigDecimal jfdkje = computeDeductDTO.getJfdkje() ;
                if(jfdkje != null){
                    zje = zje.add(jfdkje);
                }
                if("1".equals(computeDeductDTO.getDyjgmflag())){
                    if(computeDeductDTO.getDyjgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyjgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDybgmflag())){
                    if(computeDeductDTO.getDybgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDybgmje()));
                    }

                }
                if("1".equals(computeDeductDTO.getDyzgmflag())){
                    if(computeDeductDTO.getDyzgmje() != null){
                        zje = zje.subtract( (computeDeductDTO.getDyzgmje()));
                    }
                }

                dgje = zje.divide( (computeDeductDTO.getDknum()),2,BigDecimal.ROUND_HALF_UP);

                if(dgje != null){
                    if(dgje.compareTo(new BigDecimal(1800)) >= 0){
                        computeDeductDTO.setDgflag("1");
                    }else {
                        computeDeductDTO.setDgflag("2");
                    }
                }
                computeDeductDTO.setDgje(dgje);
            }else{
                computeDeductDTO.setDgje(BigDecimal.ZERO);
                computeDeductDTO.setDgflag("2");
            }
        }



        if("5".equals(computeDeductDTO.getYwlx())){
            computeDeductDTO.setDyjgmnum(computeDeductDTO.getDknum());
        }
        if("7".equals(computeDeductDTO.getYwlx())){
            computeDeductDTO.setDyzgmnum(computeDeductDTO.getDknum());
        }

        BigDecimal tczje = BigDecimal.ZERO;
        SysUser sysUser = sysUserMapper.selectUserById(temp.getUserId());
        if(sysUser != null ){
            if("1".equals(sysUser.getXsbz())){
                tczje = BigDecimal.ZERO;
            }else {
                kieSession.insert(computeDeductDTO);
                int ruleFiredCount = kieSession.fireAllRules();
                System.out.println("触发了" + ruleFiredCount + "条规则");
                System.out.println("提成金额：" + computeDeductDTO.getTcje() + "元");
                tczje = computeDeductDTO.getTcje();
                if(tczje == null){
                    tczje = BigDecimal.ZERO;
                }
                if("5".equals(temp.getYwlx())){
                    temp.setDyjtcje(tczje);
                }else if("7".equals(temp.getYwlx())){
                    temp.setDyztcje(tczje);
                }else {
                    temp.setDktcje(tczje);
                }

                if(computeDeductDTO.getDyjtcje() != null){
                    tczje = tczje.add(computeDeductDTO.getDyjtcje());
                    temp.setDyjtcje(computeDeductDTO.getDyjtcje());
                }
                if(computeDeductDTO.getDyztcje() != null){
                    tczje = tczje.add(computeDeductDTO.getDyztcje());
                    temp.setDyztcje(computeDeductDTO.getDyztcje());
                }
            }
        }

        temp.setTcje(tczje);
        return temp;
    }


    public MonthDeductDTO queryYwyDecutInfoNew(ComputeDeductDTO computeDeductDTO){

        MonthDeductDTO monthDeductDTO = new MonthDeductDTO() ;
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();
        String remark = user.getRemark();
        if(StringUtils.isNotBlank(computeDeductDTO.getRemark())){
            remark   = computeDeductDTO.getRemark();
        }
        if(computeDeductDTO.getUserid() != null ){
            monthDeductDTO.setUserid(computeDeductDTO.getUserid());
        }else{
            monthDeductDTO.setUserid(user.getUserId());
        }

        monthDeductDTO.setYwyname(user.getNickName());

        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        //将小时至0
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        //将分钟至0
        calendar.set(Calendar.MINUTE, 0);
        //将秒至0
        calendar.set(Calendar.SECOND,0);
        //将毫秒至0
        calendar.set(Calendar.MILLISECOND, 0);

        //获得当前月第一天
        Date firstDay = calendar.getTime();
        //将当前月加1；
        calendar.add(Calendar.MONTH, 1);
        //在当前月的下一月基础上减去1毫秒
        calendar.add(Calendar.MILLISECOND, -1);
        //获得当前月最后一天
        Date lastDay = calendar.getTime();
        if(computeDeductDTO.getStartDate() == null ){
            computeDeductDTO.setStartDate(firstDay);
        }
        if(computeDeductDTO.getEndDate() == null ){
            computeDeductDTO.setEndDate(lastDay);
        }
        if(computeDeductDTO.getUserid() == null){
            computeDeductDTO.setUserid(user.getUserId());
        }

        if(StringUtils.isNotBlank(remark)){
            Integer i = remark.indexOf("年");
            if(i > 0){
                String num = remark.substring(0,i);
                computeDeductDTO.setGznx(Integer.valueOf(num));
            }
        }else {
            computeDeductDTO.setGznx(0);
        }

        List<ComputeDeductDTO> list = achievementsMapper.queryYwyDkInfo(computeDeductDTO);

        if(list != null && list.size() > 0 ){
            BigDecimal xkxse = new BigDecimal(0) ; // 新开销售
            BigDecimal xktcje = new BigDecimal(0) ; //新开提成金额
            BigDecimal dktcje = new BigDecimal(0) ;  // 端口提成金额总和
            BigDecimal zxse = new BigDecimal(0) ; // 总销售额

            BigDecimal yfxxkTotal = BigDecimal.ZERO ;
            BigDecimal yfxxfTotal = BigDecimal.ZERO;
            BigDecimal yfxxktcTotal = BigDecimal.ZERO ;
            BigDecimal yfxxftcTotal = BigDecimal.ZERO ;

            BigDecimal dgjTotal = BigDecimal.ZERO ;
            BigDecimal dgjtcTotal = BigDecimal.ZERO ;

            BigDecimal phtTotal = BigDecimal.ZERO ;
            BigDecimal phttcTotal = BigDecimal.ZERO ;

            BigDecimal zsbiTotal = BigDecimal.ZERO ;
            BigDecimal zsbitcTotal = BigDecimal.ZERO ;

            BigDecimal dyjTotal = BigDecimal.ZERO ;
            BigDecimal dyjtcTotal = BigDecimal.ZERO ;

            BigDecimal dybTotal = BigDecimal.ZERO;
            BigDecimal dybtcTotal = BigDecimal.ZERO;

            BigDecimal dyzTotal = BigDecimal.ZERO;
            BigDecimal dyztcTotal = BigDecimal.ZERO;


            for(ComputeDeductDTO temp :list){
                temp.setGznx(computeDeductDTO.getGznx());
                zxse = zxse.add(temp.getZje());

                // 记录云分销新开销售额，用于计算销售额提成
                if("1".equals(temp.getYwlx()) && "1".equals(temp.getKtlx())){
                    if("1".equals(temp.getDyjgmflag())){
                        if(temp.getDyjgmje() != null){

                        }
                    }
                    if("1".equals(temp.getDybgmflag())){

                    }
                    if("1".equals(temp.getDyzgmflag())){

                    }
                    if(temp != null && temp.getZje() != null ){
                        xkxse = xkxse.add(temp.getZje());
                        if("1".equals(temp.getDyjgmflag())){
                            if(temp.getDyjgmje() != null){
                                xkxse = xkxse.subtract(temp.getDyjgmje());
                            }
                        }
                        if("1".equals(temp.getDybgmflag())){
                            if(temp.getDybgmje() != null){
                                xkxse = xkxse.subtract( (temp.getDybgmje()));
                            }
                        }
                        if("1".equals(temp.getDyzgmflag())){
                            if(temp.getDyzgmje() != null){
                                xkxse = xkxse.subtract( (temp.getDyzgmje()));
                            }
                        }
                    }
                }
                // BigDecimal tczje = temp.getTcje();
                //temp.setTcje(tczje);

                if(temp != null && temp.getDktcje() != null){
                    dktcje = dktcje.add(temp.getDktcje());
                    if(temp.getTcbdje() != null){
                        dktcje = dktcje.add(temp.getTcbdje());
                    }
                }

                if("1".equals(temp.getYwlx()) && "1".equals(temp.getKtlx())){
                    if(temp != null && temp.getDktcje() != null){
                        xktcje = xktcje.add(temp.getDktcje());
                        if(temp.getTcbdje() != null){
                            xktcje = xktcje.add(temp.getTcbdje());
                        }

                    }
                }

                // 云分销新开
                if("1".equals(temp.getYwlx()) && "1".equals(temp.getKtlx())){
                    yfxxkTotal = yfxxkTotal.add(temp.getZje());
                    if(temp.getDktcje() != null){
                        yfxxktcTotal = yfxxktcTotal.add(temp.getDktcje());
                        if(temp.getTcbdje() != null){
                            yfxxktcTotal = yfxxktcTotal.add(temp.getTcbdje());
                        }
                    }
                }
                //云分销续费
                if("1".equals(temp.getYwlx()) && "2".equals(temp.getKtlx())){
                    yfxxfTotal = yfxxfTotal.add(temp.getZje());
                    if(temp.getDktcje() != null){
                        yfxxftcTotal = yfxxftcTotal.add(temp.getDktcje());
                        if(temp.getTcbdje() != null){
                            yfxxftcTotal = yfxxftcTotal.add(temp.getTcbdje());
                        }
                    }
                }
                //店管家新开
                if("2".equals(temp.getYwlx())){
                    dgjTotal = dgjTotal.add(temp.getZje());
                    if(temp.getTcje() != null ){
                        dgjtcTotal = dgjtcTotal.add(temp.getTcje());
                    }
                }
                //拼惠团
                if("3".equals(temp.getYwlx())){
                    phtTotal = phtTotal.add(temp.getZje());
                    if(temp.getTcje() != null ){
                        phttcTotal = phttcTotal.add(temp.getTcje());
                    }
                }
                //智商BI
                if("4".equals(temp.getYwlx())){
                    zsbiTotal = zsbiTotal.add(temp.getZje());
                    if(temp.getTcje() != null ){
                        zsbitcTotal = zsbitcTotal.add(temp.getTcje());
                    }
                }
                //打印机
                if("5".equals(temp.getYwlx())){
                    dyjTotal = dyjTotal.add(temp.getZje());
                    if(temp.getTcje() != null){
                        dyjtcTotal = dyjtcTotal.add(temp.getTcje());
                    }
                }

                if("1".equals(temp.getDyjgmflag())){
                    if(temp.getDyjgmje() != null){
                        dyjTotal = dyjTotal.add( (temp.getDyjgmje()));
                    }
                    if(temp.getDyjtcje() != null){
                        dyjtcTotal = dyjtcTotal.add(temp.getDyjtcje());
                    }


                }
                //打印包
                if("6".equals(temp.getYwlx())){
                    dybTotal = dybTotal.add(temp.getZje());
                    if(temp.getTcje() != null){
                        dybtcTotal = dybtcTotal.add(temp.getTcje());
                    }
                }

                if("1".equals(temp.getDybgmflag())){
                    if(temp.getDybgmje() != null){
                        dybTotal = dybTotal.add( (temp.getDybgmje()));
                    }
                    if(temp.getDybtcje() != null){
                        dybtcTotal = dybtcTotal.add(temp.getDybtcje());
                    }

                }

                //打印纸
                if("7".equals(temp.getYwlx())){
                    dyzTotal = dyzTotal.add(temp.getZje());
                    if(temp.getTcje() != null ){
                        dyztcTotal = dyztcTotal.add(temp.getTcje());
                    }
                }

                if("1".equals(temp.getDyzgmflag())){
                    if(temp.getDyzgmje() != null){
                        dyzTotal = dyzTotal.add( (temp.getDyzgmje()));
                    }
                    if(temp.getDyztcje() != null){
                        dyztcTotal = dyztcTotal.add(temp.getDyztcje());
                    }

                }

            }

            monthDeductDTO.setZxse(zxse);
            monthDeductDTO.setXkxse(xkxse);
            monthDeductDTO.setDktcje(dktcje);
            monthDeductDTO.setYfxxkTotal(yfxxkTotal);
            monthDeductDTO.setYfxxktcTotal(yfxxktcTotal);
            monthDeductDTO.setYfxxfTotal(yfxxfTotal);
            monthDeductDTO.setYfxxftcTotal(yfxxftcTotal);
            monthDeductDTO.setDgjTotal(dgjTotal);
            monthDeductDTO.setDgjtcTotal(dgjtcTotal);
            monthDeductDTO.setPhtTotal(phtTotal);
            monthDeductDTO.setPhttcTotal(phttcTotal);
            monthDeductDTO.setZsbiTotal(zsbiTotal);
            monthDeductDTO.setZsbitcTotal(zsbitcTotal);
            monthDeductDTO.setDyjTotal(dyjTotal);
            monthDeductDTO.setDyjtcTotal(dyjtcTotal);
            monthDeductDTO.setDybTotal(dybTotal);
            monthDeductDTO.setDybtcTotal(dybtcTotal);
            monthDeductDTO.setDyzTotal(dyzTotal);
            monthDeductDTO.setDyztcTotal(dyztcTotal);
            // monthDeductDTO.setList(list);
            ComputeXseDTO computeXseDTO = new ComputeXseDTO() ;
            computeXseDTO.setXktc(xktcje); // 新开销售额提成金额
            computeXseDTO.setXkxse(xkxse); //新开销售额
            computeXseDTO.setJxse(xkxse.subtract(xktcje));
            monthDeductDTO.setXkjxse(computeXseDTO.getJxse());
            // 计算销售额提成金额
            kieSession.insert(computeXseDTO);
            int ruleFiredCount1 = kieSession.fireAllRules();
            System.out.println("销售额规则：触发了" + ruleFiredCount1 + "条规则");
            System.out.println("销售额提成金额：" + computeXseDTO.getXsetc() + "元");
            if(computeXseDTO.getXsetc() != null ){
                monthDeductDTO.setXsetcje(computeXseDTO.getXsetc().setScale(2,BigDecimal.ROUND_HALF_UP));
            }else{
                monthDeductDTO.setXsetcje(BigDecimal.ZERO);
            }

            if("1".equals(computeXseDTO.getTsflag())){
                monthDeductDTO.setTsmsg("再新开约" + computeXseDTO.getTsmsg() + "个终生端口，可享受第一档销售额提成，提成比例5%");
            }

            if("2".equals(computeXseDTO.getTsflag())){
                monthDeductDTO.setTsmsg("再新开约" + computeXseDTO.getTsmsg() + "个终生端口，可享受第二档销售额提成，提成比例10%");
            }
            if("3".equals(computeXseDTO.getTsflag())){
                monthDeductDTO.setTsmsg("再新开约" + computeXseDTO.getTsmsg() + "个终生端口，可享受第三档销售额提成，提成比例15%");
            }

            if("4".equals(computeXseDTO.getTsflag())){
                monthDeductDTO.setTsmsg("再新开约" + computeXseDTO.getTsmsg() + "个终生端口，可享受第四档销售额提成，提成比例20%");
            }

            if("5".equals(computeXseDTO.getTsflag())){
                monthDeductDTO.setTsmsg("再新开约" +  computeXseDTO.getTsmsg() + "个终生端口，可享受第五档销售额提成，提成比例25%");
            }

            if("6".equals(computeXseDTO.getTsflag())){
                monthDeductDTO.setTsmsg("您已达到享受销售额提成的第五档，提成比例25%");
            }

            // monthDeductDTO.setTsmsg(" 测试！");

            //销售额提成已取消
            /*if(computeXseDTO.getXsetc() != null ){
                monthDeductDTO.setZtcje(monthDeductDTO.getDktcje().add(computeXseDTO.getXsetc().setScale(2,BigDecimal.ROUND_HALF_UP)));

            }else {
                monthDeductDTO.setZtcje(monthDeductDTO.getDktcje().setScale(2,BigDecimal.ROUND_HALF_UP));
            }*/

            monthDeductDTO.setZtcje(monthDeductDTO.getDktcje().setScale(2,BigDecimal.ROUND_HALF_UP));
        }

        ParamDTO paramDTO = new ParamDTO();
        paramDTO.setStartDate(firstDay);
        paramDTO.setEndDate(lastDay);
        paramDTO.setUserid( computeDeductDTO.getUserid());
        MonthDeductDTO monthDeductDTO1 =  achievementsMapper.queryYwyFy(paramDTO);
        if(monthDeductDTO1 != null){
            monthDeductDTO.setFyzje(monthDeductDTO1.getFyzje());
        }
        return monthDeductDTO;
    }

    /**
     * 查询积分订单
     * @param integralOrderDTO
     * @return
     */
    @Override
    public List<IntegralOrderDTO> queryIntegralOrders(IntegralOrderDTO integralOrderDTO) {

        List<IntegralOrderDTO> list = achievementsMapper.selectIntegralOrders(integralOrderDTO);

        return list;
    }

    @Override
    public int integralOrderFh(IntegralOrderDTO integralOrderDTO) {
        int i = achievementsMapper.updateAgencyOrder(integralOrderDTO) ;
        return i;
    }

    @Override
    public List<Achievements> queryAchlistByShphone(Achievements achievements) {

        List<Achievements> list = achievementsMapper.selectAchievementsListByShpone(achievements) ;
        return list;
    }

    @Override
    public int updateGsywy(GsywyDTO gsywyDTO) {
        int i = 0 ;
        List<Achievements> list = gsywyDTO.getList();
        if(list != null && list.size() > 0 ){
            for(Achievements temp : list){
                if(StringUtils.isNotBlank(temp.getGsywy())){
                    if("1".equals(temp.getTablelx())){
                        Achievements achievements = achievementsMapper.selectAchievementsById(temp.getAchid());
                        achievements.setGsywy(temp.getGsywy());
                        i = achievementsMapper.updateAchievements(achievements);
                    }
                    if("2".equals(temp.getTablelx())){
                        Achieveold achieveold = achieveoldMapper.selectAchieveoldById(temp.getAchid());
                        achieveold.setGsywy(temp.getGsywy());
                        i = achieveoldMapper.updateAchieveold(achieveold);
                    }
                }
            }
        }
        return i;
    }
}
